From 6bd89a871559281a17fd4550c8c109e4217a8f7b Mon Sep 17 00:00:00 2001 From: Ryan Kes Date: Sat, 22 Feb 2020 20:40:41 +0100 Subject: [PATCH] Cleaned up shell scripts --- bin/.local/bin/build-suckless-desktop | 2 +- bin/.local/bin/build-suckless-thinkpad | 2 +- bin/.local/bin/calendar | 2 +- bin/.local/bin/prompt | 7 +- bin/.local/bin/vpn-switch | 20 ++--- bspwm/.local/bin/lock | 2 +- bspwm/.local/bin/maimpick | 14 ++-- bspwm/.local/bin/scratch | 2 - bspwm/.local/bin/screen_desktop | 2 +- dmenu/.local/bin/ssh-dmenu | 2 +- neomutt/.local/bin/openfile | 3 +- urlscan/.local/bin/linkhandler | 38 +++------- vifm/.config/vifm/scripts/vifmimg | 100 ++++++++++++------------- vifm/.local/bin/generate-lock-image | 14 +--- vifm/.local/bin/vifmrun | 8 +- 15 files changed, 96 insertions(+), 122 deletions(-) delete mode 100755 bspwm/.local/bin/scratch diff --git a/bin/.local/bin/build-suckless-desktop b/bin/.local/bin/build-suckless-desktop index c2a1107..ef5148b 100755 --- a/bin/.local/bin/build-suckless-desktop +++ b/bin/.local/bin/build-suckless-desktop @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env fish #Backup original cp config.h config.h.bak diff --git a/bin/.local/bin/build-suckless-thinkpad b/bin/.local/bin/build-suckless-thinkpad index 8f30ea9..a8a6f02 100755 --- a/bin/.local/bin/build-suckless-thinkpad +++ b/bin/.local/bin/build-suckless-thinkpad @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env fish # Build rm -rf src diff --git a/bin/.local/bin/calendar b/bin/.local/bin/calendar index 1afdf0b..118cb6d 100755 --- a/bin/.local/bin/calendar +++ b/bin/.local/bin/calendar @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env fish khal list read -s -n 1 diff --git a/bin/.local/bin/prompt b/bin/.local/bin/prompt index 56de2f8..e2e55d9 100755 --- a/bin/.local/bin/prompt +++ b/bin/.local/bin/prompt @@ -1,7 +1,10 @@ -#!/bin/sh +#!/usr/bin/env sh + +. ~/.cache/wal/colors.sh + # A dmenu binary prompt script. # Gives a dmenu prompt labeled with $1 to perform command $2. # For example: # `./prompt "Do you want to shutdown?" "shutdown -h now"` -[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray )" = "Yes" ] && $2 +[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray)" = "Yes" ] && $2 diff --git a/bin/.local/bin/vpn-switch b/bin/.local/bin/vpn-switch index 8f28779..c7e8306 100755 --- a/bin/.local/bin/vpn-switch +++ b/bin/.local/bin/vpn-switch @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh ### # Switch wireguard vpns up/down @@ -7,12 +7,12 @@ STATUS="$(nmcli device status | grep -c wg0)" case $STATUS in - 1) - sudo wg-quick down wg0 - notify-send 'Wireguard Down' - ;; - *) - sudo wg-quick up wg0 - notify-send 'Wireguard Up' - ;; - esac +1) + sudo wg-quick down wg0 + notify-send 'Wireguard Down' + ;; +*) + sudo wg-quick up wg0 + notify-send 'Wireguard Up' + ;; +esac diff --git a/bspwm/.local/bin/lock b/bspwm/.local/bin/lock index 15a5677..fd742f2 100755 --- a/bspwm/.local/bin/lock +++ b/bspwm/.local/bin/lock @@ -1,3 +1,3 @@ -#!/bin/sh +#!/usr/bin/env sh betterlockscreen -l blur -t "Step away from the machine!" diff --git a/bspwm/.local/bin/maimpick b/bspwm/.local/bin/maimpick index 3e01f74..5dc3c08 100755 --- a/bspwm/.local/bin/maimpick +++ b/bspwm/.local/bin/maimpick @@ -1,12 +1,12 @@ -#!/bin/sh +#!/usr/bin/env sh TIMESTAMP=$(date '+%Y-%m-%d-%H%M%S') case "$(printf "a selected area\\ncurrent window\\nfull screen\\na selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)" | dmenu -l 6 -i -p "Screenshot which area?")" in - "a selected area") maim -s ~/Pictures/Screenshots/pic-selected-"$TIMESTAMP".png && notify-send -i ~/Pictures/Screenshots/pic-selected-"$TIMESTAMP".png "Desktop Screenshot pic-selected-$TIMESTAMP.png" ;; - "current window") maim -i "$(xdotool getactivewindow)" ~/Pictures/Screenshots/pic-window-"$TIMESTAMP".png && notify-send -i ~/Pictures/Screenshots/pic-window-"$TIMESTAMP".png "Desktop Screenshot pic-window-$TIMESTAMP.png";; - "full screen") maim ~/Pictures/Screenshots/pic-full-"$TIMESTAMP".png && notify-send -i ~/Pictures/Screenshots/pic-full-"$TIMESTAMP".png "Desktop Screenshot pic-full-$TIMESTAMP.png" ;; - "a selected area (copy)") maim -s | xclip -selection clipboard -t image/png ;; - "current window (copy)") maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/png ;; - "full screen (copy)") maim | xclip -selection clipboard -t image/png ;; +"a selected area") maim -s ~/Pictures/Screenshots/pic-selected-"$TIMESTAMP".png && notify-send -i ~/Pictures/Screenshots/pic-selected-"$TIMESTAMP".png "Desktop Screenshot pic-selected-$TIMESTAMP.png" ;; +"current window") maim -i "$(xdotool getactivewindow)" ~/Pictures/Screenshots/pic-window-"$TIMESTAMP".png && notify-send -i ~/Pictures/Screenshots/pic-window-"$TIMESTAMP".png "Desktop Screenshot pic-window-$TIMESTAMP.png" ;; +"full screen") maim ~/Pictures/Screenshots/pic-full-"$TIMESTAMP".png && notify-send -i ~/Pictures/Screenshots/pic-full-"$TIMESTAMP".png "Desktop Screenshot pic-full-$TIMESTAMP.png" ;; +"a selected area (copy)") maim -s | xclip -selection clipboard -t image/png ;; +"current window (copy)") maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/png ;; +"full screen (copy)") maim | xclip -selection clipboard -t image/png ;; esac diff --git a/bspwm/.local/bin/scratch b/bspwm/.local/bin/scratch deleted file mode 100755 index 890b3f4..0000000 --- a/bspwm/.local/bin/scratch +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/sh -st -c scratchpad diff --git a/bspwm/.local/bin/screen_desktop b/bspwm/.local/bin/screen_desktop index cab8768..3ccf993 100755 --- a/bspwm/.local/bin/screen_desktop +++ b/bspwm/.local/bin/screen_desktop @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh xrandr --newmode "2560x1440_40" 201.00 2560 2720 2984 3408 1440 1443 1448 1476 -hsync +vsync xrandr --addmode HDMI-2 2560x1440_40 diff --git a/dmenu/.local/bin/ssh-dmenu b/dmenu/.local/bin/ssh-dmenu index 5d85b82..1212461 100755 --- a/dmenu/.local/bin/ssh-dmenu +++ b/dmenu/.local/bin/ssh-dmenu @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Load wal colours . ~/.cache/wal/colors.sh diff --git a/neomutt/.local/bin/openfile b/neomutt/.local/bin/openfile index 285cf6f..dba4ef1 100755 --- a/neomutt/.local/bin/openfile +++ b/neomutt/.local/bin/openfile @@ -1,5 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh # Helps open a file with xdg-open from mutt in a external program without weird side effects. opener="setsid xdg-open" $opener "$1" >/dev/null 2>&1 & - diff --git a/urlscan/.local/bin/linkhandler b/urlscan/.local/bin/linkhandler index 9ac68cb..371e8c4 100755 --- a/urlscan/.local/bin/linkhandler +++ b/urlscan/.local/bin/linkhandler @@ -1,28 +1,12 @@ -#!/bin/sh +#!/usr/bin/fish -# Feed script a url or file location. -# If an image, it will view in sxiv, -# if a video or gif, it will view in mpv -# if a music file or pdf, it will download, -# otherwise it opens link in browser. - -export BROWSER="brave" - -# Set default terminal -export TERMINAL="alacritty" - -case "$1" in - *mkv|*webm|*mp4|*youtube.com*|*youtu.be*|*hooktube.com*|*bitchute.com*) - setsid mpv --input-ipc-server=/tmp/mpvsoc"$(date +%s)" -quiet "$1" >/dev/null 2>&1 & ;; - *png|*jpg|*jpe|*jpeg|*gif) - curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///")" && sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///")" >/dev/null 2>&1 & ;; - *mp3|*flac|*opus|*mp3?source*) - setsid tsp curl -LO "$1" >/dev/null 2>&1 & ;; - *) - if [ -f "$1" ]; - then - "$TERMINAL" -e "$EDITOR $1" - else - setsid "$BROWSER" "$1" >/dev/null 2>&1 & - fi ;; -esac +switch $argv[1] + case '**.mkv' '**.webm' '**.mp4' '**youtube.com**' '**youtu.be**' '**hooktube.com**' '**bitchute.com**' '**lbry.tv**' '**.mp3' '**.flac' + setsid mpv --input-ipc-server=/tmp/mpvsoc"(date +%s)" -quiet "$argv[1]" >/dev/null 2>&1 & + case '*' + if [ -f $argv[1] ] + "$TERMINAL" -e "$EDITOR $argv[1]" + else + setsid "$BROWSER" "$argv[1]" >/dev/null 2>&1 & + end +end diff --git a/vifm/.config/vifm/scripts/vifmimg b/vifm/.config/vifm/scripts/vifmimg index 98e15c8..a7001e4 100755 --- a/vifm/.config/vifm/scripts/vifmimg +++ b/vifm/.config/vifm/scripts/vifmimg @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh readonly ID_PREVIEW="preview" #PLAY_GIF="yes" @@ -11,54 +11,54 @@ readonly ID_PREVIEW="preview" # This however, requires more CPU and therefore affects the overall performance. if [ -e "$FIFO_UEBERZUG" ]; then - if [[ "$1" == "draw" ]]; then - declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" - [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ - [path]="$PWD/$6") \ - > "$FIFO_UEBERZUG" - elif [[ "$1" == "videopreview" ]]; then - [[ ! -d "/tmp$PWD/$6/" ]] && mkdir -p "/tmp$PWD/$6/" - [[ ! -f "/tmp$PWD/$6.png" ]] && ffmpegthumbnailer -i "$PWD/$6" -o "/tmp$PWD/$6.png" -s 0 -q 10 - declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" - [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ - [path]="/tmp$PWD/$6.png") \ - > "$FIFO_UEBERZUG" - elif [[ "$1" == "gifpreview" ]]; then - [[ ! -d "/tmp$PWD/$6/" ]] && mkdir -p "/tmp$PWD/$6/" && convert -coalesce "$PWD/$6" "/tmp$PWD/$6/$6.png" - if [[ ! -z "$PLAY_GIF" ]]; then - for frame in $(ls -1 /tmp$PWD/$6/$6*.png | sort -V); do - declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" - [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ - [path]="$frame") \ - > "$FIFO_UEBERZUG" - # Sleep between frames to make the animation smooth. - sleep .07 - done - else - declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" - [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ - [path]="/tmp$PWD/$6/$6-0.png") \ - > "$FIFO_UEBERZUG" - fi - elif [[ "$1" == "epubpreview" ]]; then - [[ ! -d "/tmp$PWD/$6/" ]] && mkdir -p "/tmp$PWD/$6/" - [[ ! -f "/tmp$PWD/$6.png" ]] && epub-thumbnailer "$6" "/tmp$PWD/$6.png" 512 - declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" - [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ - [path]="/tmp$PWD/$6.png") \ - > "$FIFO_UEBERZUG" - elif [[ "$1" == "pdfpreview" ]]; then - [[ ! -d "/tmp$PWD/$6/" ]] && mkdir -p "/tmp$PWD/$6/" - [[ ! -f "/tmp$PWD/$6.png" ]] && pdftoppm -png -singlefile "$6" "/tmp$PWD/$6" - declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" - [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ - [path]="/tmp$PWD/$6.png") \ - > "$FIFO_UEBERZUG" - elif [[ "$1" == "clear" ]]; then - declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \ - > "$FIFO_UEBERZUG" - [[ ! -z $AUTO_REMOVE ]] && [[ -f "/tmp$PWD/$6.png" ]] && rm -f "/tmp$PWD/$6.png" - [[ ! -z $AUTO_REMOVE ]] && [[ -d "/tmp$PWD/$6/" ]] && rm -rf "/tmp$PWD/$6/" + if [[ "$1" == "draw" ]]; then + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" + [path]="$PWD/$6") \ + >"$FIFO_UEBERZUG" + elif [[ "$1" == "videopreview" ]]; then + [[ ! -d "/tmp$PWD/$6/" ]] && mkdir -p "/tmp$PWD/$6/" + [[ ! -f "/tmp$PWD/$6.png" ]] && ffmpegthumbnailer -i "$PWD/$6" -o "/tmp$PWD/$6.png" -s 0 -q 10 + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" + [path]="/tmp$PWD/$6.png") \ + >"$FIFO_UEBERZUG" + elif [[ "$1" == "gifpreview" ]]; then + [[ ! -d "/tmp$PWD/$6/" ]] && mkdir -p "/tmp$PWD/$6/" && convert -coalesce "$PWD/$6" "/tmp$PWD/$6/$6.png" + if [[ ! -z "$PLAY_GIF" ]]; then + for frame in $(ls -1 /tmp$PWD/$6/$6*.png | sort -V); do + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" + [path]="$frame") \ + >"$FIFO_UEBERZUG" + # Sleep between frames to make the animation smooth. + sleep .07 + done + else + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" + [path]="/tmp$PWD/$6/$6-0.png") \ + >"$FIFO_UEBERZUG" + fi + elif [[ "$1" == "epubpreview" ]]; then + [[ ! -d "/tmp$PWD/$6/" ]] && mkdir -p "/tmp$PWD/$6/" + [[ ! -f "/tmp$PWD/$6.png" ]] && epub-thumbnailer "$6" "/tmp$PWD/$6.png" 512 + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" + [path]="/tmp$PWD/$6.png") \ + >"$FIFO_UEBERZUG" + elif [[ "$1" == "pdfpreview" ]]; then + [[ ! -d "/tmp$PWD/$6/" ]] && mkdir -p "/tmp$PWD/$6/" + [[ ! -f "/tmp$PWD/$6.png" ]] && pdftoppm -png -singlefile "$6" "/tmp$PWD/$6" + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" + [path]="/tmp$PWD/$6.png") \ + >"$FIFO_UEBERZUG" + elif [[ "$1" == "clear" ]]; then + declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \ + >"$FIFO_UEBERZUG" + [[ ! -z $AUTO_REMOVE ]] && [[ -f "/tmp$PWD/$6.png" ]] && rm -f "/tmp$PWD/$6.png" + [[ ! -z $AUTO_REMOVE ]] && [[ -d "/tmp$PWD/$6/" ]] && rm -rf "/tmp$PWD/$6/" - fi + fi fi diff --git a/vifm/.local/bin/generate-lock-image b/vifm/.local/bin/generate-lock-image index b3a4de5..e6c49e1 100755 --- a/vifm/.local/bin/generate-lock-image +++ b/vifm/.local/bin/generate-lock-image @@ -1,13 +1,3 @@ -#!/bin/sh +#!/usr/bin/env sh -clear - -WIDTH=$(xrandr | grep '\*' | awk -F 'x' '{print $1}' | sed 's/ //g') -OUTPUT_IMAGE="$HOME/.cache/lock.png" - -echo "Converting ${1} to ${OUTPUT_IMAGE}...." -convert "${1}" "${OUTPUT_IMAGE}" -echo "done!" -echo "Reszing ${OUTPUT_IMAGE} to width ${WIDTH}...." -convert "${OUTPUT_IMAGE}" -resize "${WIDTH}"x "${OUTPUT_IMAGE}" -echo "done!" +betterlockscreen -u $1 diff --git a/vifm/.local/bin/vifmrun b/vifm/.local/bin/vifmrun index 8764c88..3c66d07 100755 --- a/vifm/.local/bin/vifmrun +++ b/vifm/.local/bin/vifmrun @@ -1,9 +1,9 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}" -function cleanup { - rm "$FIFO_UEBERZUG" 2>/dev/null - pkill -P $$ 2>/dev/null +function cleanup() { + rm "$FIFO_UEBERZUG" 2>/dev/null + pkill -P $$ 2>/dev/null } pkill -P $$ 2>/dev/null rm "$FIFO_UEBERZUG" 2>/dev/null