diff options
Diffstat (limited to '.local')
-rwxr-xr-x | .local/bin/pick | 38 | ||||
-rwxr-xr-x | .local/bin/x-pdf | 9 | ||||
-rwxr-xr-x | .local/bin/x-terminal-emulator | 12 | ||||
-rwxr-xr-x | .local/bin/x-www-browser | 14 |
4 files changed, 45 insertions, 28 deletions
diff --git a/.local/bin/pick b/.local/bin/pick new file mode 100755 index 0000000..ed2d44d --- /dev/null +++ b/.local/bin/pick @@ -0,0 +1,38 @@ +#!/bin/bash + +cmd=${0##*/} + +if [[ $1 = -h ]]; then + echo "Usage: $cmd PROG1 PROG2 PROG3..." + echo " $cmd -s PROG1 PROG2 PROG3..." + echo "" + echo "If \`-s' ISN'T given, print the first program name given that is" + echo "found in PATH." + echo "" + echo "If \`-s' IS given, print the first program name given that is" + echo "currently running. If no match is found, fall back to default" + echo "behavior." + exit 0 +fi + +if [[ $1 = -s ]]; then + shift + # Scan to find a running instance + for prog in "$@"; do + if [[ -n "`pgrep $prog`" ]]; then + printf '%s\n' "$prog" + exit 0 + fi + done +fi + +# Scan to find one that is installed +for prog in "$@"; do + if [[ -x "`which $prog 2>/dev/null`" ]]; then + printf '%s\n' "$prog" + exit 0 + fi +done + +printf '%s\n' "$cmd: no suitable program found" +exit 1 diff --git a/.local/bin/x-pdf b/.local/bin/x-pdf index a9893c0..1b23a3d 100755 --- a/.local/bin/x-pdf +++ b/.local/bin/x-pdf @@ -1,9 +1,4 @@ #!/bin/sh -if [ -x "`which okular 2>/dev/null`" ]; then - okular "$@" -elif [ -x "`which evince 2>/dev/null`" ]; then - evince "$@" -elif [ -x "`which xpdf 2>/dev/null`" ]; then - xpdf "$@" -fi +`pick evince okular xpdf` "$@" +exit $? diff --git a/.local/bin/x-terminal-emulator b/.local/bin/x-terminal-emulator index f7290b4..049b081 100755 --- a/.local/bin/x-terminal-emulator +++ b/.local/bin/x-terminal-emulator @@ -1,10 +1,4 @@ #!/bin/sh -if [ -x "`which emacsterm`" ]; then - emacsterm $@ -elif [ -x "`which urxvt`" ]; then - urxvt $@ -elif [ -x "`which gnome-terminal`" ]; then - gnome-terminal $@ -elif [ -x "`which xterm`"]; then - xterm $@ -fi + +`pick emacsterm urxvt gnome-terminal xterm` "$@" +exit $? diff --git a/.local/bin/x-www-browser b/.local/bin/x-www-browser index 0ead72a..bbd8943 100755 --- a/.local/bin/x-www-browser +++ b/.local/bin/x-www-browser @@ -1,14 +1,4 @@ #!/bin/sh -list='firefox iceweasel icecat conkeror' - -looking=true -for prog in $list; do - if $looking && [ -n "`pgrep $prog`" ]; then - $prog $@ - looking=false - fi -done -if $looking; then - conkeror $@ -fi +`pick -s conkeror iceweasel icecat firefox` "$@" +exit $? |