Browse Source

Modularized and added an ROFI/DMENU completion for screen layouts

Samuel W. Flint 8 years ago
parent
commit
6153d31ccd
1 changed files with 34 additions and 13 deletions
  1. 34 13
      switch-layout

+ 34 - 13
switch-layout

@@ -1,29 +1,50 @@
 #!/bin/zsh -f
 
 if [[ $# -eq 0 ]] ; then
-    echo "switch-layout [ name | list | define ]"
+    echo "switch-layout [ name | list | dmenu | define ]"
     exit
 fi
 
 LAYOUT=$1
 
+function list-layouts () {
+    for layout in ~/.screenlayout/*.sh ;
+    do
+        echo "$(basename -- ${layout} .sh)"
+    done
+}
+
+function apply-layout () {
+    if [[ -e ~/.screenlayout/${LAYOUT}.sh ]] ; then
+        sh ~/.screenlayout/${LAYOUT}.sh
+        [[ -e ~/.screenlayout/${LAYOUT}.sh-after ]] && \
+            sh ~/.screenlayout/${LAYOUT}.sh-after
+        echo Switched to ${LAYOUT} layout
+    else
+        echo "${LAYOUT} not available"
+    fi
+}
+
+function with-external-completion () {
+    if [[ -e `which rofi` ]] ; then
+        LAYOUT=`echo define | list-layouts | rofi -dmenu -p layout:`
+        [[ $LAYOUT != "" ]] && apply-layout
+    else
+        LAYOUT=`echo define | list-layouts | dmenu -p layout:`
+        [[ $LAYOUT != "" ]] && apply-layout
+    fi
+}
+
 case ${LAYOUT} in
     define)
         arandr
         ;;
     list)
-        for layout in ~/.screenlayout/*.sh ;
-        do
-            echo " - $(basename -- ${layout} .sh)"
-        done
+        list-layouts
+        ;;
+    dmenu)
+        with-external-completion
         ;;
     *)
-        if [[ -e ~/.screenlayout/${LAYOUT}.sh ]] ; then
-            sh ~/.screenlayout/${LAYOUT}.sh
-            [[ -e ~/.screenlayout/${LAYOUT}.sh-after ]] && \
-                sh ~/.screenlayout/${LAYOUT}.sh-after
-            echo Switched to ${LAYOUT} layout
-        else
-            echo "${LAYOUT} not available"
-        fi
+        apply-layout
 esac