Various Minor Scripts
I prefer using tiny scripts to aliases because it saves me going around to all my open terminals and re-sourcing .profile, and I have them available from contexts that aren't my main shell. This is the collection of those scripts that aren't machine-specific.
Fair warning: these are shop built jigs and may lack niceties like polite usage strings when given bad parameters.
Not everything is documented here. Some scripts are self-explanatory.
Perform an rsync backup to
backup home DSTHOST or
backup full DSTHOST
Use vmenu to choose from a list of existent X clients to switch to, or bring to the current workspace.
bringwindow -a to switch to window, or
bringwindow -R to bring the window to your current workspace.
Manages 'drawer terminal' type programs, like a generalized version of
guake or so.
drawer NAME [SIDE WIDTH HEIGHT COMMAND]
NAMEis a symbolic name for the drawer. It should be a valid POSIX filename.
SIDEis the side of the screen to attach the drawer to. Valid values are
HEIGHTmay be either a size in pixels or a percentage of screen size (
84%) specifying the dimensions of the window to create.
COMMANDis the command with arguments which will actually create the window.
drawer looks in
/tmp/drawers.wids/ for a file called
NAME containing an X window id. If found, that window's
hidden EWMH hint will be toggled. If the file is not found,
COMMAND is executed and the resulting window is positioned according
HEIGHT and then focused, and the windows X window id is written to
/tmp/drawers.wids/$NAME to allow future toggling.
Launch gvim on a new file under
~/writing/journal with a name generated by the
Output the current time in
YYYYMMDD:HHMM.SS (epoch+UNIXTIME) format.
Read and append a (editably, if interactive) timestamped line to
mknote in a loop, for e.g. keeping a drawer term to collect and show notes.
Poor-person's version of
watch(1). Repeatedly run a command at a specified frequency, clearing the terminal before each execution.
obsess DELAY COMMAND...
DELAY is the (floating point) number of seconds between invokations of
obsess 1 date if it's not clear what this script is for.
Remote clipboard with logging; replaces Pocket, Pinboard, etc with a very small shell script.
ssh (public key auth highly recommended) and
xclip to use clipboard manipulation funcionality.
To use, put in
PATH on each host you wish to use it on, and also on a net-accessible server, and update the
RSH_CMD variable at the head of the script with the
ssh command necessary to log into your server, and
touch rclip.clip; touch rclip.log. Then:
rclip copy [-a] [METADATA] SELECTION: store the contents of SELECTION to your
rclip paste SELECTION: read the contents of the
rclipclip from your server into SELECTION.
rclip put [-a] [METADATA]: read from
STDINand store to the
rclipclip on your server.
rclip get: print the contents of the
rclipclip from your server to
rclip tail: follow the
rcliplog, printing each new clip as it's stored.
STDOUTprints the output of
rclip tail, while each line passed to
STDINis posted as a new clip. Lines are read using the
readcommand with no
-rargument, so newlines can be escaped using
SELECTION is one of the standard X selection names as understood by
clipboard. Defaults to
METADATA is a string that will be inserted into the item header alongside the datestamp when logging. This can be any number of shell parameters, or a single string.
-a argument to
put causes the data to be appended to the current clip, rather than replacing it (and likewise, appended to the current log entry, rather than opening a new one).
rclip also accepts a
-c CLIPNAME argument before the operation, e.g.
rclip -c foo put .... If supplied, this specifies an alternate clip to use. This can be any filename-safe string and is inserted into the name of the clip and log files, so that instead of reading/writing from e.g.
rclip -c foo put will write to
rclip.foo.log. Note the potential security implication here: it's theoretically possible to use this option to cause
rclip to write to any file your user can access.
rclip uses many short-lived
ssh connections and is much better and significantly faster when used with public-key authentication and SSH Connection Sharing.
sesh (Session Helper)
sesh is a simple script to help restore your session state when using a dynamic window manager. For me the big use case is that I use individual browser windows managed by my window manager rather than browser tabs, so when I have to reboot, log in/out, etc, it's a pain moving the windows back to the desks I had them on.
- Before logout, shutdown, etc, invoke
seshwith all your windows still open. A list of window names and associated desktop numbers will be saved at
- After login and reloading apps, browser sessions, etc, invoke
sesh load, and it will move all you windows to the desktops specified in
- There is a function
mungeat the top of the script that is used to process window titles to eliminate volatile elements like GMail's message count or Slack's unread indicator. This is necessary since windows must be identified by title substring.
scut (Super | Simple | Suckless) cut.
An improved version of the POSIX
scut FIELDSPEC,[FIELDSPEC[,...]] [-dDELIMITER] [-jJOINER]
FIELDSPEC is either an integer, or a range of the form
n-m. If it is an integer, that field (zero-based) from each line of
STDIN will be printed to
STDOUT. If it is a range, fields
n (inclusive) through
m (exclusive) will be printed.
n also allows the special field separator
^ which causes all fields from the beginning of the line until field
m to be printed, verbatim, without replacing field separators with field joiners. Similarly,
m supports the special value
$ which prints from field
n through the end of the line, verbatim.
DELIMITER is any regex supported by the Pyton 2 regex module and is used to split input lines into fields.
JOINER is the string used to join fields together in the output. Escape sequences such as '\t' will be processed into their represented characters.
cut command, fields specified multiple times will be printed multiple times.
WARNING: contains python. A Golang version is in the works.
vmenu to select a line from
STDIN (assumed to be output from the
history command) and print it to
STDOUT. Intended to be used from your shell's
readline to place a selection from your history on the command line for editing.
man with the given arguments, and display the outputs in a new terminal window.
dmenu in vertical format, with multi-token matching, and the given arguments. Falls back to
slmenu if not running in an X session.
$BROWSER with the given arguments.