OSDN Git Service

dswitch accept arguments
authorpaperbenni <paperbenni@gmail.com>
Mon, 16 Dec 2019 17:18:31 +0000 (18:18 +0100)
committerpaperbenni <paperbenni@gmail.com>
Mon, 16 Dec 2019 17:18:31 +0000 (18:18 +0100)
dswitch

diff --git a/dswitch b/dswitch
index 41c5f11..d3c8bd7 100755 (executable)
--- a/dswitch
+++ b/dswitch
@@ -5,21 +5,26 @@
 ## does not change to respective monitor    ##
 ##############################################
 
-# Date format, for use as the prompt.
-date=$(date +"%a %d. %b %R")
+if ! [ -n "$1" ]; then
+    # Date format, for use as the prompt.
+    date=$(date +"%a %d. %b %R")
+
+    # dmenu cannot display more than 30 lines, to avoid screen clutter. Only relevant if you have more than 30 windows open.
+    height=$(wmctrl -l | wc -l)
+    if [[ $height -gt 30 ]]; then
+        heightfit=30
+    else
+        heightfit=$height
+    fi
 
-# dmenu cannot display more than 30 lines, to avoid screen clutter. Only relevant if you have more than 30 windows open.
-height=$(wmctrl -l | wc -l)
-if [[ $height -gt 30 ]]; then
-    heightfit=30
+    num=$(wmctrl -l | sed 's/  / /' | cut -d " " -f 4- | nl -w 3 -n rn | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' | dmenu -b -i -p "$date" -l $heightfit | cut -d '-' -f -1)
+    [[ -z "$num" ]] && exit
+
+    WID=$(wmctrl -l | sed -n "$num p" | cut -c -10)
 else
-    heightfit=$height
+    WID="$1"
 fi
 
-num=$(wmctrl -l | sed 's/  / /' | cut -d " " -f 4- | nl -w 3 -n rn | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' | dmenu -b -i -p "$date" -l $heightfit | cut -d '-' -f -1)
-[[ -z "$num" ]] && exit
-
-WID=$(wmctrl -l | sed -n "$num p" | cut -c -10)
 echo "focus target $WID"
 
 focuswin() {