Skip to content
jasondunsmore edited this page Sep 13, 2010 · 48 revisions

INTRO

This solution allows you to have access to a large number of one-liners and makes them available for use on remote systems without having to cut & paste. Dmenu is the interface, which makes it easy to manage thousands of menu items quickly, since it dynamically narrows down results based on your keystrokes. Dmenu cats the output of the one-liners into xclip, then xdotool mimics Shift-Insert to paste the output of your one-liner into the remote server without executing it, so that you can modify it before executing.

This git repo is for sharing the one-liners. Contact JasonD or MattB for write access.

REQUIREMENTS

dmenu
xdotool
xclip
git

INSTALLATION

Install script and dependencies

Install dmenu, xdotool, and xclip

apt-get install dmenu xdotool xclip git-core

Install the snippets script

Put the following in ~/bin/snippets:

#!/bin/bash
rs=~/rhel-snippets
exe=$( ls -B $rs | dmenu -b )
echo $exe >> $rs/.stats
cat $rs/$exe | sed -e '/^\#/d' -e '/^$/d' | perl -pe 'chop if eof' | xclip
xdotool key "shift+Insert"

Also see Variations on the snippets script for how to display documentation, implement keybindings, or install the script on KDE.

Make the script executable:

chmod +x ~/bin/snippets

Also make sure $HOME/bin is in your $PATH.

Clone git repository

cd
git clone git://github.com/jasondunsmore/rhel-snippets.git

Bind the snippets script to a keybinding in your window manager

Gnome (Metacity)

Install gconf-editor if you don’t have it, then edit the keybindings under apps – metacity – keybinding_commands and apps – metacity – global keybindings. More detailed instructions

KDE

Use kmenuedit to create a new menu item and then apply a shortcut to it.

Sawfish

(bind-keys global-keymap
    "M-S-s" (lambda () (system "snippets &")))

Ratpoison

bind d exec /home/mattb/scripts/snippets

(Please add instructions for different window managers here)

Create a github account to contribute (optional)

Create a github.com account and contact Jason for write access.

Naming conventions

Scripts should be named with the most general descriptor first. Descriptors should be separated by hyphens.

Scripting conventions

Multi-line scripts should end with “\” (backslash) so bash treats them as the same line. This will prevent scripts from executing automatically.

Comments should describe what the script does and give an example of the script output (when applicable).

Scripts with arguments that are buried in the middle of the line should use a bash function to move arguments to the end of the line.

For example:


function dropips () { for ip in $*; do iptables -I INPUT -s $ip -j DROP; done && iptables -L }; dropips