diff --git a/bin/clam-shell.sh b/bin/clam-shell.sh index 6679f7f..7ebe594 100755 --- a/bin/clam-shell.sh +++ b/bin/clam-shell.sh @@ -18,7 +18,7 @@ # along with this program. If not, see . if grep -q open /proc/acpi/button/lid/LID/state; then - swaymsg output eDP-1 enable + swaymsg output eDP-1 enable else - swaymsg output eDP-1 disable + swaymsg output eDP-1 disable fi diff --git a/bin/cycle-focus.sh b/bin/cycle-focus.sh index fa7ac2a..f583f5d 100755 --- a/bin/cycle-focus.sh +++ b/bin/cycle-focus.sh @@ -19,58 +19,57 @@ reverse="" while getopts "hr" opt; do - case "$opt" in - h|help) - echo "Usage: cycle-focus.sh OPTIONS target [runstring]" - echo - echo "Cycle focus through the windows on the current workspace." - echo - echo "OPTIONS" - echo "-r|--reverse cycle in reverse (NOT YET IMPLEMENTED)" - exit 0 - ;; - r|reverse) - reverse="set" - ;; - esac + case "$opt" in + h | help) + echo "Usage: cycle-focus.sh OPTIONS target [runstring]" + echo + echo "Cycle focus through the windows on the current workspace." + echo + echo "OPTIONS" + echo "-r|--reverse cycle in reverse (NOT YET IMPLEMENTED)" + exit 0 + ;; + r | reverse) + reverse="set" + ;; + esac done -workspace=$( swaymsg -t get_workspaces | - jq -r '.[] | select(.focused==true) | .name' | - awk -F':' '{print $1}' ) +workspace=$(swaymsg -t get_workspaces | + jq -r '.[] | select(.focused==true) | .name' | + awk -F':' '{print $1}') -focused=$( swaymsg -t get_tree | jq '.. | select(.type?) | - select(.focused==true) | .id' ) +focused=$(swaymsg -t get_tree | jq '.. | select(.type?) | + select(.focused==true) | .id') -window_ids=($( swaymsg -t get_tree | - jq -r --arg ws $workspace ' +window_ids=($(swaymsg -t get_tree | + jq -r --arg ws $workspace ' .. | select(.type?=="workspace" and .name==$ws) | recurse(.nodes[]) | select(.name != null and .type?=="con") | - .id' )) + .id')) if [ -n "$reverse" ]; then - min=0 - max=$(( ${#window_ids[@]} -1 )) - while [[ min -lt max ]] - do - x="${window_ids[$min]}" - window_ids[$min]="${window_ids[$max]}" - window_ids[$max]="$x" - (( min++, max-- )) - done + min=0 + max=$((${#window_ids[@]} - 1)) + while [[ min -lt max ]]; do + x="${window_ids[$min]}" + window_ids[$min]="${window_ids[$max]}" + window_ids[$max]="$x" + ((min++, max--)) + done fi if [ -n "$window_ids" ]; then - found_focused=false - for window in "${window_ids[@]}"; do - if $found_focused; then - swaymsg "[con_id=$window] focus" - exit 0 - fi - if [ "$window" = "$focused" ]; then - found_focused=true - fi - done - first_window=$(echo "$window_ids" | head -n 1) - swaymsg "[con_id=$first_window]" focus + found_focused=false + for window in "${window_ids[@]}"; do + if $found_focused; then + swaymsg "[con_id=$window] focus" + exit 0 + fi + if [ "$window" = "$focused" ]; then + found_focused=true + fi + done + first_window=$(echo "$window_ids" | head -n 1) + swaymsg "[con_id=$first_window]" focus fi diff --git a/bin/fuzzel-files.sh b/bin/fuzzel-files.sh index c28ba58..6a518de 100755 --- a/bin/fuzzel-files.sh +++ b/bin/fuzzel-files.sh @@ -20,16 +20,17 @@ cd $HOME file=1 while [ "$file" ]; do - file=$(ls -1 --group-directories-first | fuzzel -d -p "$(basename $(pwd))") - if [ -e "$file" ]; then - owd=$(pwd) - if [ -d "$file" ]; then - cd "$file" - else [ -f "$file" ] - if which xdg-open &> /dev/null; then - exec xdg-open "$owd/$file" & - unset file - fi + file=$(ls -1 --group-directories-first | fuzzel -d -p "$(basename $(pwd))") + if [ -e "$file" ]; then + owd=$(pwd) + if [ -d "$file" ]; then + cd "$file" + else + [ -f "$file" ] + if which xdg-open &>/dev/null; then + exec xdg-open "$owd/$file" & + unset file + fi + fi fi - fi done diff --git a/bin/new-workspace.sh b/bin/new-workspace.sh index 5499cd8..90b5476 100755 --- a/bin/new-workspace.sh +++ b/bin/new-workspace.sh @@ -18,38 +18,37 @@ # along with this program. If not, see . while getopts "hdt" opt; do - case "$opt" in - h|help) - echo "Usage: new-workspace.sh [OPTIONS]" - echo "Switch to the lowest unused workspace." - echo - echo "OPTIONS" - echo "-t, --take-focused take the current window with you" - exit 0 - ;; - d|debug) - debug="1" - shift - ;; - t|take-focused) - take=$( swaymsg -t get_tree | - jq '.. | select(.type?) | select(.focused==true) | .id' ) - shift - ;; + case "$opt" in + h | help) + echo "Usage: new-workspace.sh [OPTIONS]" + echo "Switch to the lowest unused workspace." + echo + echo "OPTIONS" + echo "-t, --take-focused take the current window with you" + exit 0 + ;; + d | debug) + debug="1" + shift + ;; + t | take-focused) + take=$(swaymsg -t get_tree | + jq '.. | select(.type?) | select(.focused==true) | .id') + shift + ;; esac done -workspaces=($( swaymsg -t get_workspaces | jq -r '.[].num' | sort -n )) +workspaces=($(swaymsg -t get_workspaces | jq -r '.[].num' | sort -n)) next_workspace=$(echo "${workspaces[@]}" | - awk -v RS='\\s+' ' + awk -v RS='\\s+' ' { a[$1] } END { for(i = 1; i in a; ++i); print i }') [[ "$debug" ]] && { - for i in ${workspaces[@]} - do - echo "WORKSPACES: $i" - done - echo "NEXT: $next_workspace" + for i in ${workspaces[@]}; do + echo "WORKSPACES: $i" + done + echo "NEXT: $next_workspace" } [[ "$take" ]] && swaymsg "move window to workspace $next_workspace" diff --git a/bin/run-or-raise.sh b/bin/run-or-raise.sh index d4600cd..cc0998b 100755 --- a/bin/run-or-raise.sh +++ b/bin/run-or-raise.sh @@ -19,6 +19,6 @@ swaymsg "[app_id=$1] focus" >/dev/null 2>&1 || { swaymsg "[class=$1] focus" >/dev/null 2>&1 || { - swaymsg exec "$2" + swaymsg exec "$2" } } diff --git a/bin/screenshot.sh b/bin/screenshot.sh index 5381bf0..5837be9 100755 --- a/bin/screenshot.sh +++ b/bin/screenshot.sh @@ -18,14 +18,10 @@ # along with this program. If not, see . for prog in grim slurp; do - if which "$prog" &> /dev/null; then - grim -g "$(slurp)" - notify-send -t 3000 "Screenshot" "Saved in $GRIM_DEFAULT_DIR" - else - notify-send "Install GRIM and SLURP." - fi + if which "$prog" &>/dev/null; then + grim -g "$(slurp)" + notify-send -t 3000 "Screenshot" "Saved in $GRIM_DEFAULT_DIR" + else + notify-send "Install GRIM and SLURP." + fi done - - - - diff --git a/bin/select-theme.sh b/bin/select-theme.sh index 077c26a..5e03889 100755 --- a/bin/select-theme.sh +++ b/bin/select-theme.sh @@ -21,13 +21,13 @@ if [[ -n "$1" ]]; then theme="$1" else theme=$(echo -e "day\nnight\nmorning\nbright\nacme" | - fuzzel -d -l 6 -p "Select theme > "); + fuzzel -d -l 6 -p "Select theme > ") fi case $theme in - day) +day) cp ~/.config/alacritty/themes/tomorrow-day.toml \ - ~/.config/alacritty/colors.toml + ~/.config/alacritty/colors.toml gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Base-Grey gsettings set org.gnome.desktop.interface color-scheme prefer-light emacsclient -e "(load-theme-disable-others 'drh-tomorrow-day)" @@ -43,9 +43,9 @@ case $theme in sed -i '/^selection-match=/c\selection-match=c82829ff' ~/.config/fuzzel/fuzzel.ini sed -i '/^counter=/c\counter=8e908cff' ~/.config/fuzzel/fuzzel.ini ;; - night) +night) cp ~/.config/alacritty/themes/tomorrow-night.toml \ - ~/.config/alacritty/colors.toml + ~/.config/alacritty/colors.toml gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Dark-Grey gsettings set org.gnome.desktop.interface color-scheme prefer-dark emacsclient -e "(load-theme-disable-others 'drh-tomorrow-night)" @@ -61,9 +61,9 @@ case $theme in sed -i '/^selection-match=/c\selection-match=cc6666ff' ~/.config/fuzzel/fuzzel.ini sed -i '/^counter=/c\counter=969896ff' ~/.config/fuzzel/fuzzel.ini ;; - morning) +morning) cp ~/.config/alacritty/themes/tomorrow-morning.toml \ - ~/.config/alacritty/colors.toml + ~/.config/alacritty/colors.toml gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Base-Grey gsettings set org.gnome.desktop.interface color-scheme prefer-light emacsclient -e "(load-theme-disable-others 'drh-tomorrow-morning)" @@ -79,9 +79,9 @@ case $theme in sed -i '/^selection-match=/c\selection-match=c82829ff' ~/.config/fuzzel/fuzzel.ini sed -i '/^counter=/c\counter=8e908cff' ~/.config/fuzzel/fuzzel.ini ;; - bright) +bright) cp ~/.config/alacritty/themes/tomorrow-bright.toml \ - ~/.config/alacritty/colors.toml + ~/.config/alacritty/colors.toml gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Dark-Grey gsettings set org.gnome.desktop.interface color-scheme prefer-dark emacsclient -e "(load-theme-disable-others 'drh-tomorrow-bright)" @@ -97,9 +97,9 @@ case $theme in sed -i '/^selection-match=/c\selection-match=d54e53ff' ~/.config/fuzzel/fuzzel.ini sed -i '/^counter=/c\counter=969896ff' ~/.config/fuzzel/fuzzel.ini ;; - acme) +acme) cp ~/.config/alacritty/themes/acme.toml \ - ~/.config/alacritty/colors.toml + ~/.config/alacritty/colors.toml gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Base-Grey gsettings set org.gnome.desktop.interface color-scheme prefer-dark emacsclient -e "(load-theme-disable-others 'drh-mono-acme)" @@ -114,5 +114,5 @@ case $theme in sed -i '/^selection-text=/c\selection-text=4d4d4cff' ~/.config/fuzzel/fuzzel.ini sed -i '/^selection-match=/c\selection-match=c82829ff' ~/.config/fuzzel/fuzzel.ini sed -i '/^counter=/c\counter=8e908cff' ~/.config/fuzzel/fuzzel.ini - ;; + ;; esac diff --git a/bin/select-window.sh b/bin/select-window.sh index 5090d4f..75d1374 100755 --- a/bin/select-window.sh +++ b/bin/select-window.sh @@ -26,7 +26,6 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. - set -e # error if a command as non 0 exit set -u # error if undefined variable @@ -76,57 +75,55 @@ Examples: " # Options parsing -INVALID_ARGS=0 +INVALID_ARGS=0 OPTS=$(getopt -n $NAME -o f:d:hv \ - --long format:,dmenu-cmd:,help,version -- "$@") || INVALID_ARGS=1 + --long format:,dmenu-cmd:,help,version -- "$@") || INVALID_ARGS=1 # Exit with error and print $HELP if an invalid argument is passed # the previous command is allowed to fail for this purpose -if [ "$INVALID_ARGS" -ne "0" ] -then - echo "$HELP" - exit 1 +if [ "$INVALID_ARGS" -ne "0" ]; then + echo "$HELP" + exit 1 fi # Required for getopt parsing eval set -- "$OPTS" unset OPTS -while : -do - case "$1" in - -f | --format) - FORMAT=$2 - shift 2 - ;; - -d | --dmenu-cmd) - DMENU=$2 - shift 2 - ;; - -h | --help) - echo "$HELP" - exit - ;; - -v | --version) - echo "Version $VERSION" - exit - ;; - --) - shift - break - ;; - *) - echo "$HELP" - exit 1 - break - ;; - esac +while :; do + case "$1" in + -f | --format) + FORMAT=$2 + shift 2 + ;; + -d | --dmenu-cmd) + DMENU=$2 + shift 2 + ;; + -h | --help) + echo "$HELP" + exit + ;; + -v | --version) + echo "Version $VERSION" + exit + ;; + --) + shift + break + ;; + *) + echo "$HELP" + exit 1 + break + ;; + esac done # FORMAT as a `jq` concatenation string FORMAT="$FORMAT (%I)" -FORMAT=$(echo "$FORMAT" | \ - sed 's/%O/" + .output + "/ +FORMAT=$(echo "$FORMAT" | + sed 's/%O/" + .output + "/ s/%W/" + .workspace + "/ s/%A/" + .app_id + "/ s/%T/" + .name + "/ @@ -135,8 +132,8 @@ FORMAT=$(echo "$FORMAT" | \ s/\(.*\)/\"\1\"/') # Get the container ID from the node tree -CON_ID=$(swaymsg -t get_tree | \ - jq -r ".nodes[] +CON_ID=$(swaymsg -t get_tree | + jq -r ".nodes[] | {output: .name, content: .nodes[]} | {output: .output, workspace: .content.name, apps: .content @@ -146,8 +143,8 @@ CON_ID=$(swaymsg -t get_tree | \ | {output: .output, workspace: .workspace, id: .apps.id, app_id: .apps.app_id, name: .apps.name } | $FORMAT - | tostring" | \ - $DMENU -i -p "Window Switcher > ") + | tostring" | + $DMENU -i -p "Window Switcher > ") # Requires the actual `id` to be at the end and between paretheses CON_ID=${CON_ID##*(}