P2O2 WWW
Useful Scripts
Scripting Snippets at Hand
Created - Apr 31, 2007 | Modified - Sep 20, 2007
P2O2 WWW Homepage -> Useful Scripts -> Scripting Snippets at Hand
Setting Demands
- Independent of Programming Editors
- Covering Different Scripting Languages
- Edit Snippet Option
- Save New Snippet Option
Script Name
xrsd_snippets_PROG_LANG
where
PROG = scripting language, e.g. rexx, bash, perl, etc
LANG = message language (country, locale), e.g. en, pl
XRSD in a script name which stands for Xdialog Rapid Script Development in imitation of RAD (Rapid Application Development). This module is part of a small set of scripts which make scripting more convenient.
I will describe xrsd_snippets_bash_en program/script.
ATTENTION
xrsd_snippets_bash_en script "blinks" during switching or copying to clipboard. Xdialog gives script programmer modules only, which are being closed after running. To keep them on desktop they must be run in artificial "loopback" (semi-recursive invocation).
External Applications
This script needs following applications:
- Xclip (clipboard application) -> xclip-0.08nb2 - command line interface to the X windows clipboard
- Xdialog (set of GTK+ 1.2 widget modules) -> xdialog-2.1.1nb3 - X11 drop-in replacement for the curses dialog program
- Nedit (any programming editor) -> nedit-5.5nb3 - Motif based standard GUI style text editor
Setting xrsd_snippets_bash_en
Every new script covering new scripting language should have changed descriptive variables. The changes are marked with red color.
#-------------------------------------------------#
# directory declarations
#-------------------------------------------------#
dir_path="${HOME}/lnbsd/tmpl.bash.en"
dir_scripts="${HOME}/lnbsd/scripts"
this_script="xrsd_snippets_bash_en"
#-------------------------------------------------#
# declaring external editor
#-------------------------------------------------#
ext_editor="nedit -column 85 -row 20"
#-------------------------------------------------#
# defining Xdialog common attributes
#-------------------------------------------------#
ti="LearN@BSD - XRSD" # ti - title
bt="LearN@BSD Newbie Primer\n\
Bash/Xdialog Scripting Modules" # bt - title
dm='230x700+794+0 8' # dm - dimensions: menubox
de='650x500+374+0' # de - dimensions: editbox
Creating Snippets
All scripting snippets are put into ~/lnbsd/templates.db directory tree.
I have only three subdirectories for Bash in English, Bash in Polish, and Rexx in English.
These subdirectories have their symlinks in ~/lnbsd/.
- ~/lnbsd/templates.db/tmpl.bash.en
- ~/lnbsd/templates.db/tmpl.bash.pl
- ~/lnbsd/templates.db/tmpl.rexx.en
Snippet directories contain bogus files with wako names like m----------, rc_----------, etc They divide snippet list in application window into programming categories. See screenshots further in the text.
xrsd_snippets_bash_en Usage
# Package: Xdialog Rapid Script Development (xrsd)
# File: xrsd_menu_PROG_LANG
# (PROG = programming language)
# (LANG = message language, e.g. en or pl)
#
# In short: Handy Scripting Snippets Independent of Editors
#
# Descr.: Script opens Xdialog editbox where you can
# select file then copy its contents into your
# script with help of middle mouse button (MMB).
# The standard Unix copy via MBB can be simulated
# by pressing left (1) and right (3) mouse buttons
# simultaneously. Triggered edit window enables
# to change the contents.
#
# Usage: Button COPY or double click copies selected file
# to clipboard.
# Button On/Off EDIT switch edit trigger.
#
# If EDIT is OFF:
# 1) first item in list will be 00_EDIT_OFF
# 2) selected file is copied to clipboard as
# in COPY case
#
# If EDIT is ON:
# 1) first item in list will be 00_EDIT_ON
# 2) selected file will be opened in external
# editor AND
# 3) copied to clipboard as in COPY case
#
# Xdialog window closing - press top right
# [X] button (on title bar)
#
# Caveat: Some systems don't pay attention to Xdialog
# window's placement attributes
P2O2 Screenshots
Picture 1: Leafpad editor with xrsd_snippets_bash_en. 00_EDIT_OFF file in xrsd_snippets_bash_eb window showed automagically (default). (click to enlarge)
Picture 2: I clicked "header" snippet then pasted it to editor window. Look at the editor - copied text contains wrong Internet addresses and date. I needed to correct that. (click to enlarge)
Picture 3: So I pressed right button [On/Off Edit]. New file on top of the list showed. It told me that xrsd_snippets_bash_en switched to EDIT mode. (click to enlarge)
Picture 4: Next I double clicked "header" item from list and Nedit editor appeared with the "header" file contents. Then I made changes to internet addresses (new data are shown). But Nedit enable us to make new snippet as well. So I opened new tab, entered there some text and saved it under c_comment_10.
Picture 5: New snippet c_comment_10 in full view.
Picture 6: As you can see xrsd_snippets_bash_en was switched off from EDIT mode (00_EDIT_OFF is visible). The new snippet c_comment_10 was pasted into Leafpad editor. Do not pay attention to additional c_comment_10 with .bck expansion. My Nedit is set to make copies. (click to enlarge)
Picture 7: And last touch of xrsd_snippets_bash_en, new corrected header was inserted to Leafpad edit area (marked). (click to enlarge)
Download Files
1.) lnbsd.handysnippets.tar.gz
|