summaryrefslogtreecommitdiff
path: root/.local/bin/pick
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-01-27 20:52:59 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-01-27 20:52:59 -0500
commit786fcda41a731654dd2de7496d5f28bc7bb19743 (patch)
treeab557aa22a6463fd15667ec738b12f7fd78d7aa1 /.local/bin/pick
parent614636d8e5a1f643d3c91d0d5e52482aef38bb5e (diff)
parent5f7de477be298f158369862c1a3cc80286fc7e32 (diff)
Merge remote-tracking branch 'origin/master' into build64-par
Conflicts: .kde/share/apps .kde/share/config .kde4
Diffstat (limited to '.local/bin/pick')
-rwxr-xr-x.local/bin/pick38
1 files changed, 38 insertions, 0 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