From 17df35dc088c9b1b159c2b78d8330fa9cc9a672a Mon Sep 17 00:00:00 2001 From: filip <“filip.rabiega@gmail.com”> Date: Wed, 21 Jan 2026 23:42:15 +0100 Subject: reformat most scripts --- batterylow | 10 ++-- bmks | 61 +++++++++++++---------- brightness | 4 +- cht.sh | 74 ++++++++++++++-------------- dbdb | 14 +++--- dictloop | 20 ++++---- dmenu-translate | 150 +++++++++++++++++++++++++++++--------------------------- dpass | 2 +- dtrans | 150 +++++++++++++++++++++++++++++--------------------------- dz-feed | 6 +-- echovol | 4 +- engadd | 2 +- inpath | 50 +++++++++---------- logrm | 8 +-- lsn | 2 +- maimpick | 2 +- mansplain | 2 +- mounter | 114 +++++++++++++++++++++--------------------- newnote | 22 ++++----- newscript | 26 +++++----- notesplain | 4 +- printpath | 4 +- rmw | 16 +++--- rssadd | 4 +- rssget | 86 ++++++++++++++++---------------- saferm | 30 ++++++------ scan | 6 +-- sysact | 46 ++++++++--------- todo | 20 ++++---- via | 18 +++---- via-feed | 30 ++++++------ via-open | 102 +++++++++++++++++++------------------- volume | 8 +-- wrocwttr | 4 +- 34 files changed, 561 insertions(+), 540 deletions(-) diff --git a/batterylow b/batterylow index 0f2ebd4..85cdf5d 100755 --- a/batterylow +++ b/batterylow @@ -5,18 +5,18 @@ battery=$(upower -e | grep BAT | head -n 1) percentage=$(upower -i "$battery" | - awk '/percentage/ {gsub(/%/, "", $2); print $2}') + awk '/percentage/ {gsub(/%/, "", $2); print $2}') state=$(upower -i "$battery" | - awk '/state/ {print $2}') + awk '/state/ {print $2}') # Only notify if the battery is discharging if [ "$state" != "discharging" ]; then - exit 0 + exit 0 fi if [ "$percentage" -le 5 ]; then - notify-send "Battery very low." + notify-send "Battery very low." elif [ "$percentage" -le 15 ]; then - notify-send "Battery low." + notify-send "Battery low." fi diff --git a/bmks b/bmks index b0a9b4f..8733643 100755 --- a/bmks +++ b/bmks @@ -11,7 +11,7 @@ URL_FILE_PATH="$HOME/.config/bmks" URL_FILE_NAME="urls" show_usage() { - printf "bmks: unix bookmark management that sucks less + printf "bmks: unix bookmark management that sucks less usage: bmks help @@ -33,47 +33,56 @@ If you would prefer to have your bookmarks stored in alternate location there ar } bmks_add() { - [ -z "$url" ] && printf "Error: url must be provided\n\n" && show_usage && exit 0 - printf "Description: " - read -r description - [ -z "$description" ] && echo "$url" >> $URL_FILE_PATH/$URL_FILE_NAME - [ -n "$description" ] && echo "$description - $url" >> $URL_FILE_PATH/$URL_FILE_NAME + [ -z "$url" ] && printf "Error: url must be provided\n\n" && show_usage && exit 0 + printf "Description: " + read -r description + [ -z "$description" ] && echo "$url" >>$URL_FILE_PATH/$URL_FILE_NAME + [ -n "$description" ] && echo "$description - $url" >>$URL_FILE_PATH/$URL_FILE_NAME } bmks_ls() { - bmks_check - cat $URL_FILE_PATH/$URL_FILE_NAME | sort + bmks_check + cat $URL_FILE_PATH/$URL_FILE_NAME | sort } bmks_del() { - bmks_check - case $PREFERED_LAUNCHER in - dmenu) sed -i "/$(cat $URL_FILE_PATH/$URL_FILE_NAME | sort | dmenu -i -l 15 )/d" $URL_FILE_PATH/$URL_FILE_NAME ;; - fzf) sed -i "/$(cat $URL_FILE_PATH/$URL_FILE_NAME | sort | fzf)/d" $URL_FILE_PATH/$URL_FILE_NAME ;; - esac + bmks_check + case $PREFERED_LAUNCHER in + dmenu) sed -i "/$(cat $URL_FILE_PATH/$URL_FILE_NAME | sort | dmenu -i -l 15)/d" $URL_FILE_PATH/$URL_FILE_NAME ;; + fzf) sed -i "/$(cat $URL_FILE_PATH/$URL_FILE_NAME | sort | fzf)/d" $URL_FILE_PATH/$URL_FILE_NAME ;; + esac } bmks_display() { - bmks_check - case $PREFERED_LAUNCHER in - dmenu) cat $URL_FILE_PATH/$URL_FILE_NAME | sort | dmenu -i -l 15 | awk '{print $(NF)}' | xargs -I '{}' $BROWSER {} ;; - fzf) cat $URL_FILE_PATH/$URL_FILE_NAME | sort | fzf | awk '{print $(NF)}' | xargs -I '{}' $BROWSER {} ;; - esac + bmks_check + case $PREFERED_LAUNCHER in + dmenu) cat $URL_FILE_PATH/$URL_FILE_NAME | sort | dmenu -i -l 15 | awk '{print $(NF)}' | xargs -I '{}' $BROWSER {} ;; + fzf) cat $URL_FILE_PATH/$URL_FILE_NAME | sort | fzf | awk '{print $(NF)}' | xargs -I '{}' $BROWSER {} ;; + esac } bmks_check() { - [ ! -s $URL_FILE_PATH/$URL_FILE_NAME ] && printf "Error: No bookmarks found to display. Try adding some!\n\n" && show_usage && exit 0 + [ ! -s $URL_FILE_PATH/$URL_FILE_NAME ] && printf "Error: No bookmarks found to display. Try adding some!\n\n" && show_usage && exit 0 } [ ! -d $URL_FILE_PATH ] && mkdir $URL_FILE_PATH [ ! -f $URL_FILE_PATH/$URL_FILE_NAME ] && touch $URL_FILE_PATH/$URL_FILE_NAME case "$1" in - "help") show_usage ;; - "add") url=$2; bmks_add ;; - "del") bmks_del ;; - "ls") bmks_ls ;; - "dmenu") PREFERED_LAUNCHER=$1; bmks_display ;; - "fzf") PREFERED_LAUNCHER=$1; bmks_display ;; - *) bmks_display ;; +"help") show_usage ;; +"add") + url=$2 + bmks_add + ;; +"del") bmks_del ;; +"ls") bmks_ls ;; +"dmenu") + PREFERED_LAUNCHER=$1 + bmks_display + ;; +"fzf") + PREFERED_LAUNCHER=$1 + bmks_display + ;; +*) bmks_display ;; esac diff --git a/brightness b/brightness index b2c81c9..024b581 100755 --- a/brightness +++ b/brightness @@ -2,6 +2,6 @@ # This script is for managing system brightness. It is envoked by dwm. case "$1" in - up) sudo brightnessctl s "10%+" ;; - down) sudo brightnessctl s "10%-" ;; +up) sudo brightnessctl s "10%+" ;; +down) sudo brightnessctl s "10%-" ;; esac diff --git a/cht.sh b/cht.sh index f3d2bc0..776757e 100755 --- a/cht.sh +++ b/cht.sh @@ -48,8 +48,8 @@ export LESSSECURE=1 STEALTH_MAX_SELECTION_LENGTH=5 case "$(uname -s)" in - Darwin) is_macos=yes ;; - *) is_macos=no ;; +Darwin) is_macos=yes ;; +*) is_macos=no ;; esac # for KSH93 @@ -122,10 +122,10 @@ EOF local dependencies=(python git virtualenv) for dep in "${dependencies[@]}"; do command -v "$dep" >/dev/null || - { - echo "DEPENDENCY: \"$dep\" is needed to install cheat.sh in the standalone mode" >&2 - _exit_code=1 - } + { + echo "DEPENDENCY: \"$dep\" is needed to install cheat.sh in the standalone mode" >&2 + _exit_code=1 + } done [ "$_exit_code" -ne 0 ] && return "$_exit_code" @@ -136,8 +136,8 @@ EOF [ -n "$_installdir" ] && installdir=$_installdir if [ "$installdir" = y ] || - [ "$installdir" = Y ] || - [ "$(echo "$installdir" | tr "[:upper:]" "[:lower:]")" = yes ]; then + [ "$installdir" = Y ] || + [ "$(echo "$installdir" | tr "[:upper:]" "[:lower:]")" = yes ]; then echo Please enter the directory name echo If it was the directory name already, please prepend it with \"./\": "./$installdir" else @@ -201,7 +201,7 @@ EOF _say_what_i_do Creating virtual environment virtualenv "${virtualenv_python3_option[@]}" ve || - fatal "Could not create virtual environment with 'virtualenv ve'" + fatal "Could not create virtual environment with 'virtualenv ve'" export CHEATSH_PATH_WORKDIR=$PWD @@ -214,15 +214,15 @@ EOF _say_what_i_do Installing python requirements into the virtual environment ve/bin/"$pip" install -r requirements.txt >"$LOG" || - { - - echo "ERROR:" - echo "---" - tail -n 10 "$LOG" - echo "---" - echo "See $LOG for more" - fatal Could not install python dependencies into the virtual environment - } + { + + echo "ERROR:" + echo "---" + tail -n 10 "$LOG" + echo "---" + echo "See $LOG for more" + fatal Could not install python dependencies into the virtual environment + } echo "$(ve/bin/"$pip" freeze | wc -l) dependencies were successfully installed" _say_what_i_do Fetching the upstream cheat sheets repositories @@ -324,8 +324,8 @@ get_query_options() { local query="$*" if [ -n "$CHTSH_QUERY_OPTIONS" ]; then case $query in - *\?*) query="$query&${CHTSH_QUERY_OPTIONS}" ;; - *) query="$query?${CHTSH_QUERY_OPTIONS}" ;; + *\?*) query="$query&${CHTSH_QUERY_OPTIONS}" ;; + *) query="$query?${CHTSH_QUERY_OPTIONS}" ;; esac fi printf "%s" "$query" @@ -420,12 +420,12 @@ elif [ "$(uname -s)" = OpenBSD ] && [ -x /usr/bin/ftp ]; then local opt args="-o -" while getopts "b:s" opt; do case $opt in - b) args="$args -c $OPTARG" ;; - s) args="$args -M -V" ;; - *) - echo "internal error: unsupported cURL option '$opt'" >&2 - exit 1 - ;; + b) args="$args -c $OPTARG" ;; + s) args="$args -M -V" ;; + *) + echo "internal error: unsupported cURL option '$opt'" >&2 + exit 1 + ;; esac done shift $((OPTIND - 1)) @@ -508,8 +508,8 @@ else valid_sections=$(get_list_of_sections) valid=no for q in $valid_sections; do [ "$q" = "$new_section/" ] && { - valid=yes - break + valid=yes + break }; done if [ "$valid" = yes ]; then @@ -561,17 +561,17 @@ cmd_cd() { valid_sections=$(get_list_of_sections) valid=no for q in $valid_sections; do [ "$q" = "$new_section/" ] && { - valid=yes - break + valid=yes + break }; done if [ "$valid" = no ]; then echo "Invalid section: $new_section" echo "Valid sections:" echo "$valid_sections" | - xargs printf "%-10s\n" | - tr ' ' . | - xargs -n 10 | - sed 's/\./ /g; s/^/ /' + xargs printf "%-10s\n" | + tr ' ' . | + xargs -n 10 | + sed 's/\./ /g; s/^/ /' else section="$new_section" fi @@ -803,7 +803,7 @@ while true; do cmd_name=${input%% *} cmd_args=${input#* } case $cmd_name in - "") continue ;; # skip empty input lines + "") continue ;; # skip empty input lines '?' | h | help) cmd_name=help ;; hush) cmd_name=hush ;; cd) cmd_name="cd" ;; @@ -818,6 +818,6 @@ while true; do cmd_name="query" cmd_args="$input" ;; -esac -"cmd_$cmd_name" $cmd_args + esac + "cmd_$cmd_name" $cmd_args done diff --git a/dbdb b/dbdb index 2fb1581..de9eb43 100755 --- a/dbdb +++ b/dbdb @@ -8,11 +8,11 @@ chosen="placeholder" while [ ! -z "$chosen" ]; do - DIRs=$( ls -a1p | grep -P '^\w[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1') - DOTDs=$( ls -a1p | grep -P '^\.[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1') - FILEs=$( ls -a1p | grep -P '^\w[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1') - DOTFs=$( ls -a1p | grep -P '^\.[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1') - clear && printf "\e[1;7;33m $(pwd) \e[0m\n$FILEs\n\e[0;38;5;238m$DOTFs\e[0m\n" - chosen=`( ( echo -e "$DIRs$DOTDs" | awk -vRS="\t" -vORS="\n" '1' ) | dmenu -i )` - cd "$chosen" + DIRs=$(ls -a1p | grep -P '^\w[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1') + DOTDs=$(ls -a1p | grep -P '^\.[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1') + FILEs=$(ls -a1p | grep -P '^\w[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1') + DOTFs=$(ls -a1p | grep -P '^\.[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1') + clear && printf "\e[1;7;33m $(pwd) \e[0m\n$FILEs\n\e[0;38;5;238m$DOTFs\e[0m\n" + chosen=$( (echo -e "$DIRs$DOTDs" | awk -vRS="\t" -vORS="\n" '1') | dmenu -i) + cd "$chosen" done diff --git a/dictloop b/dictloop index 1a239ea..b58f56f 100755 --- a/dictloop +++ b/dictloop @@ -3,25 +3,25 @@ # Load aliases if available if [ -n "$ZDOTDIR" ] && [ -f "$ZDOTDIR/aliasrc" ]; then - . "$ZDOTDIR/aliasrc" + . "$ZDOTDIR/aliasrc" fi # Argument check if [ "$#" -ne 1 ]; then - echo "Usage: dictloop " >&2 - exit 1 + echo "Usage: dictloop " >&2 + exit 1 fi dict=$1 while :; do - printf "Enter a word: " - read -r word + printf "Enter a word: " + read -r word - if [ -z "$word" ] || [ "$word" = "exit" ]; then - echo "Exiting..." - exit 0 - fi + if [ -z "$word" ] || [ "$word" = "exit" ]; then + echo "Exiting..." + exit 0 + fi - "$dict" "$word" + "$dict" "$word" done diff --git a/dmenu-translate b/dmenu-translate index 766ad51..a9ed163 100755 --- a/dmenu-translate +++ b/dmenu-translate @@ -1,16 +1,16 @@ #!/bin/sh echo_err() { - notify-send -u critical "$0 error" "$1" + notify-send -u critical "$0 error" "$1" } err() { - echo_err "$1" - exit 1 + echo_err "$1" + exit 1 } check_dep() { - command -v "$1" > /dev/null || err "$1 is required: $2" + command -v "$1" >/dev/null || err "$1 is required: $2" } # We don't check if dmenu is installed because someone @@ -19,96 +19,99 @@ check_dep trans https://github.com/soimort/translate-shell check_dep notify-send load_config() { - config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/dmenu-translate" - [ -d "$config_dir" ] || mkdir -p "$config_dir" - - config_file="$config_dir/config.sh" - [ -f "$config_file" ] || touch "$config_file" - - old_config_file="$config_dir/config.conf" - [ -f "$old_config_file" ] && notify-send "dmenu-translate warning" "Found old configuration file at $old_config_file, which is no longer supported. Please move your settings to a new file at $config_file and delete the old one." - - . "$config_file" - - # Check others - if [ -n "$WAYLAND_DISPLAY" ]; then - : "${CLIP_COPY:=wl-copy -n}" - : "${CLIP_PASTE_CLIP:=wl-paste}" - : "${CLIP_PASTE_PRIM:=wl-paste -p}" - : "${DMENU:=wmenu}" - : "${TERMINAL=foot}" - else - : "${CLIP_COPY:=xclip -i -r -selection clipboard}" - : "${CLIP_PASTE_CLIP:=xclip -o -selection clipboard}" - : "${CLIP_PASTE_PRIM:=xclip -o -selection primary}" - : "${DMENU:=dmenu}" - : "${TERMINAL=xterm}" - fi - - # Default values - : "${TRANS_LANGS:=:ru :en}" - : "${DMENU_TEXT:=${DMENU} -i -p 'Translate: Text'}" - : "${DMENU_LANG:=${DMENU} -i -p 'Translate: Into'}" - : "${DMENU_NEXT:=${DMENU} -i -p 'Translate: Next?'}" + config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/dmenu-translate" + [ -d "$config_dir" ] || mkdir -p "$config_dir" + + config_file="$config_dir/config.sh" + [ -f "$config_file" ] || touch "$config_file" + + old_config_file="$config_dir/config.conf" + [ -f "$old_config_file" ] && notify-send "dmenu-translate warning" "Found old configuration file at $old_config_file, which is no longer supported. Please move your settings to a new file at $config_file and delete the old one." + + . "$config_file" + + # Check others + if [ -n "$WAYLAND_DISPLAY" ]; then + : "${CLIP_COPY:=wl-copy -n}" + : "${CLIP_PASTE_CLIP:=wl-paste}" + : "${CLIP_PASTE_PRIM:=wl-paste -p}" + : "${DMENU:=wmenu}" + : "${TERMINAL=foot}" + else + : "${CLIP_COPY:=xclip -i -r -selection clipboard}" + : "${CLIP_PASTE_CLIP:=xclip -o -selection clipboard}" + : "${CLIP_PASTE_PRIM:=xclip -o -selection primary}" + : "${DMENU:=dmenu}" + : "${TERMINAL=xterm}" + fi + + # Default values + : "${TRANS_LANGS:=:ru :en}" + : "${DMENU_TEXT:=${DMENU} -i -p 'Translate: Text'}" + : "${DMENU_LANG:=${DMENU} -i -p 'Translate: Into'}" + : "${DMENU_NEXT:=${DMENU} -i -p 'Translate: Next?'}" } formatmenu() { - echo "$1" | tr '\n' ' ' | sed 's/\s\{3,\}//g; s/^\(.\{30\}\).\+/\1.../; s/$/\n/' + echo "$1" | tr '\n' ' ' | sed 's/\s\{3,\}//g; s/^\(.\{30\}\).\+/\1.../; s/$/\n/' } get_selection() { - [ -n "$1" ] && eval "$CLIP_PASTE_CLIP" || eval "$CLIP_PASTE_PRIM" + [ -n "$1" ] && eval "$CLIP_PASTE_CLIP" || eval "$CLIP_PASTE_PRIM" } clip_menu() { - { formatmenu "$1"; formatmenu "$2"; } | - sed 's/^\s*$//; 1s/^./Primary: &/; 2s/^./Clipboard: &/' | - sed '/^$/d' + { + formatmenu "$1" + formatmenu "$2" + } | + sed 's/^\s*$//; 1s/^./Primary: &/; 2s/^./Clipboard: &/' | + sed '/^$/d' } lang_menu() { - echo "$TRANS_LANGS" | sed 's/\s\+/\n/g' | sed '/:/!s/^/:/' - echo '[Define]' + echo "$TRANS_LANGS" | sed 's/\s\+/\n/g' | sed '/:/!s/^/:/' + echo '[Define]' } choose_next() { - t="$1" - shift - if [ -n "$ALWAYS_COPY" ]; then - echo 'Copy' - else - eval "$DMENU_NEXT" "$@" <<-EOF + t="$1" + shift + if [ -n "$ALWAYS_COPY" ]; then + echo 'Copy' + else + eval "$DMENU_NEXT" "$@" <<-EOF Copy: $(formatmenu "$t") Copy temp file name View EOF - fi + fi } save_file() ( - tmp="$(mktemp --tmpdir 'dmenu-translate.XXXXXX')" - echo "$1" > "$tmp" - echo "$tmp" + tmp="$(mktemp --tmpdir 'dmenu-translate.XXXXXX')" + echo "$1" >"$tmp" + echo "$tmp" ) open_term() { - ${TERMINAL} -e ${PAGER:-'less'} "$(save_file "$1")" + ${TERMINAL} -e ${PAGER:-'less'} "$(save_file "$1")" } get_text() { - echo "$2" | while IFS= read -r clip; do - [ "$1" = "$clip" ] && { - type="$(echo "$clip" | sed 's/^\(\w\+\):.*/\1/')" - case "$type" in - Primary) echo "$primary" ;; - Clipboard) echo "$clipboard" ;; - esac - exit 10 - } - done - - # If not found, just echo text - [ $? -ne 10 ] && echo "$1" + echo "$2" | while IFS= read -r clip; do + [ "$1" = "$clip" ] && { + type="$(echo "$clip" | sed 's/^\(\w\+\):.*/\1/')" + case "$type" in + Primary) echo "$primary" ;; + Clipboard) echo "$clipboard" ;; + esac + exit 10 + } + done + + # If not found, just echo text + [ $? -ne 10 ] && echo "$1" } # Config @@ -129,9 +132,9 @@ target="$(lang_menu | eval "$DMENU_LANG" "$@")" || exit 0 # If Define chosen, define term and exit [ "$target" = '[Define]' ] && { - dict="$(trans -dictionary "$text")" - open_term "$(trans -dictionary "$text")" - exit 0 + dict="$(trans -dictionary "$text")" + open_term "$(trans -dictionary "$text")" + exit 0 } # Translate text @@ -139,10 +142,13 @@ translation="$(trans -b "$target" "$text")" [ -z "$translation" ] && err 'Failed to translate' case "$(choose_next "$translation" "$@")" in - 'View') open_term "$translation"; exit 0 ;; +'View') + open_term "$translation" + exit 0 + ;; 'Copy temp file name') output="$(save_file "$translation")" ;; -'Copy'*) output="$translation" ;; -*) exit 0 ;; +'Copy'*) output="$translation" ;; +*) exit 0 ;; esac echo "$output" | eval "$CLIP_COPY" || err 'Failed to copy! Is CLIP_COPY setting set properly?' diff --git a/dpass b/dpass index 60adce3..fd37cfc 100755 --- a/dpass +++ b/dpass @@ -3,5 +3,5 @@ dir="${PASSWORD_STORE_DIR:-$HOME/.password-store}" password=$(find "$dir" -type f -name '*.gpg' | - sed 's/.*\/\(.*\)\.gpg$/\1/' | dmenu -i -p "Pass:") + sed 's/.*\/\(.*\)\.gpg$/\1/' | dmenu -i -p "Pass:") [ -n "$password" ] && pass show -c "$password" diff --git a/dtrans b/dtrans index 766ad51..a9ed163 100755 --- a/dtrans +++ b/dtrans @@ -1,16 +1,16 @@ #!/bin/sh echo_err() { - notify-send -u critical "$0 error" "$1" + notify-send -u critical "$0 error" "$1" } err() { - echo_err "$1" - exit 1 + echo_err "$1" + exit 1 } check_dep() { - command -v "$1" > /dev/null || err "$1 is required: $2" + command -v "$1" >/dev/null || err "$1 is required: $2" } # We don't check if dmenu is installed because someone @@ -19,96 +19,99 @@ check_dep trans https://github.com/soimort/translate-shell check_dep notify-send load_config() { - config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/dmenu-translate" - [ -d "$config_dir" ] || mkdir -p "$config_dir" - - config_file="$config_dir/config.sh" - [ -f "$config_file" ] || touch "$config_file" - - old_config_file="$config_dir/config.conf" - [ -f "$old_config_file" ] && notify-send "dmenu-translate warning" "Found old configuration file at $old_config_file, which is no longer supported. Please move your settings to a new file at $config_file and delete the old one." - - . "$config_file" - - # Check others - if [ -n "$WAYLAND_DISPLAY" ]; then - : "${CLIP_COPY:=wl-copy -n}" - : "${CLIP_PASTE_CLIP:=wl-paste}" - : "${CLIP_PASTE_PRIM:=wl-paste -p}" - : "${DMENU:=wmenu}" - : "${TERMINAL=foot}" - else - : "${CLIP_COPY:=xclip -i -r -selection clipboard}" - : "${CLIP_PASTE_CLIP:=xclip -o -selection clipboard}" - : "${CLIP_PASTE_PRIM:=xclip -o -selection primary}" - : "${DMENU:=dmenu}" - : "${TERMINAL=xterm}" - fi - - # Default values - : "${TRANS_LANGS:=:ru :en}" - : "${DMENU_TEXT:=${DMENU} -i -p 'Translate: Text'}" - : "${DMENU_LANG:=${DMENU} -i -p 'Translate: Into'}" - : "${DMENU_NEXT:=${DMENU} -i -p 'Translate: Next?'}" + config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/dmenu-translate" + [ -d "$config_dir" ] || mkdir -p "$config_dir" + + config_file="$config_dir/config.sh" + [ -f "$config_file" ] || touch "$config_file" + + old_config_file="$config_dir/config.conf" + [ -f "$old_config_file" ] && notify-send "dmenu-translate warning" "Found old configuration file at $old_config_file, which is no longer supported. Please move your settings to a new file at $config_file and delete the old one." + + . "$config_file" + + # Check others + if [ -n "$WAYLAND_DISPLAY" ]; then + : "${CLIP_COPY:=wl-copy -n}" + : "${CLIP_PASTE_CLIP:=wl-paste}" + : "${CLIP_PASTE_PRIM:=wl-paste -p}" + : "${DMENU:=wmenu}" + : "${TERMINAL=foot}" + else + : "${CLIP_COPY:=xclip -i -r -selection clipboard}" + : "${CLIP_PASTE_CLIP:=xclip -o -selection clipboard}" + : "${CLIP_PASTE_PRIM:=xclip -o -selection primary}" + : "${DMENU:=dmenu}" + : "${TERMINAL=xterm}" + fi + + # Default values + : "${TRANS_LANGS:=:ru :en}" + : "${DMENU_TEXT:=${DMENU} -i -p 'Translate: Text'}" + : "${DMENU_LANG:=${DMENU} -i -p 'Translate: Into'}" + : "${DMENU_NEXT:=${DMENU} -i -p 'Translate: Next?'}" } formatmenu() { - echo "$1" | tr '\n' ' ' | sed 's/\s\{3,\}//g; s/^\(.\{30\}\).\+/\1.../; s/$/\n/' + echo "$1" | tr '\n' ' ' | sed 's/\s\{3,\}//g; s/^\(.\{30\}\).\+/\1.../; s/$/\n/' } get_selection() { - [ -n "$1" ] && eval "$CLIP_PASTE_CLIP" || eval "$CLIP_PASTE_PRIM" + [ -n "$1" ] && eval "$CLIP_PASTE_CLIP" || eval "$CLIP_PASTE_PRIM" } clip_menu() { - { formatmenu "$1"; formatmenu "$2"; } | - sed 's/^\s*$//; 1s/^./Primary: &/; 2s/^./Clipboard: &/' | - sed '/^$/d' + { + formatmenu "$1" + formatmenu "$2" + } | + sed 's/^\s*$//; 1s/^./Primary: &/; 2s/^./Clipboard: &/' | + sed '/^$/d' } lang_menu() { - echo "$TRANS_LANGS" | sed 's/\s\+/\n/g' | sed '/:/!s/^/:/' - echo '[Define]' + echo "$TRANS_LANGS" | sed 's/\s\+/\n/g' | sed '/:/!s/^/:/' + echo '[Define]' } choose_next() { - t="$1" - shift - if [ -n "$ALWAYS_COPY" ]; then - echo 'Copy' - else - eval "$DMENU_NEXT" "$@" <<-EOF + t="$1" + shift + if [ -n "$ALWAYS_COPY" ]; then + echo 'Copy' + else + eval "$DMENU_NEXT" "$@" <<-EOF Copy: $(formatmenu "$t") Copy temp file name View EOF - fi + fi } save_file() ( - tmp="$(mktemp --tmpdir 'dmenu-translate.XXXXXX')" - echo "$1" > "$tmp" - echo "$tmp" + tmp="$(mktemp --tmpdir 'dmenu-translate.XXXXXX')" + echo "$1" >"$tmp" + echo "$tmp" ) open_term() { - ${TERMINAL} -e ${PAGER:-'less'} "$(save_file "$1")" + ${TERMINAL} -e ${PAGER:-'less'} "$(save_file "$1")" } get_text() { - echo "$2" | while IFS= read -r clip; do - [ "$1" = "$clip" ] && { - type="$(echo "$clip" | sed 's/^\(\w\+\):.*/\1/')" - case "$type" in - Primary) echo "$primary" ;; - Clipboard) echo "$clipboard" ;; - esac - exit 10 - } - done - - # If not found, just echo text - [ $? -ne 10 ] && echo "$1" + echo "$2" | while IFS= read -r clip; do + [ "$1" = "$clip" ] && { + type="$(echo "$clip" | sed 's/^\(\w\+\):.*/\1/')" + case "$type" in + Primary) echo "$primary" ;; + Clipboard) echo "$clipboard" ;; + esac + exit 10 + } + done + + # If not found, just echo text + [ $? -ne 10 ] && echo "$1" } # Config @@ -129,9 +132,9 @@ target="$(lang_menu | eval "$DMENU_LANG" "$@")" || exit 0 # If Define chosen, define term and exit [ "$target" = '[Define]' ] && { - dict="$(trans -dictionary "$text")" - open_term "$(trans -dictionary "$text")" - exit 0 + dict="$(trans -dictionary "$text")" + open_term "$(trans -dictionary "$text")" + exit 0 } # Translate text @@ -139,10 +142,13 @@ translation="$(trans -b "$target" "$text")" [ -z "$translation" ] && err 'Failed to translate' case "$(choose_next "$translation" "$@")" in - 'View') open_term "$translation"; exit 0 ;; +'View') + open_term "$translation" + exit 0 + ;; 'Copy temp file name') output="$(save_file "$translation")" ;; -'Copy'*) output="$translation" ;; -*) exit 0 ;; +'Copy'*) output="$translation" ;; +*) exit 0 ;; esac echo "$output" | eval "$CLIP_COPY" || err 'Failed to copy! Is CLIP_COPY setting set properly?' diff --git a/dz-feed b/dz-feed index 85c7c54..0b595ad 100755 --- a/dz-feed +++ b/dz-feed @@ -4,9 +4,9 @@ cache="$HOME/.cache/dz" if [ "$1" = "-r" ] || [ ! -e "$cache" ]; then - find "$HOME" -mindepth 1 \( -name ".*" -o -path "$HOME/cell" -o -path "$HOME/phone/*" \) -prune -o -print | \ - sed '/\.pdf$/!d' | sort > "$cache" - # notify-send "dz cache updated." + find "$HOME" -mindepth 1 \( -name ".*" -o -path "$HOME/cell" -o -path "$HOME/phone/*" \) -prune -o -print | + sed '/\.pdf$/!d' | sort >"$cache" + # notify-send "dz cache updated." fi cat "$cache" diff --git a/echovol b/echovol index 8413c1b..f0cc86a 100755 --- a/echovol +++ b/echovol @@ -5,7 +5,7 @@ volume=$(pactl list sinks | grep -A 15 'Sink #0' | grep 'Volume:' | awk '{print mute=$(pactl list sinks | grep -A 15 'Sink #0' | grep 'Mute' | awk '{print $2}') if [ "$mute" = "yes" ]; then - echo "mute" + echo "mute" else - echo "$volume%" + echo "$volume%" fi diff --git a/engadd b/engadd index 1d91cf5..d849e70 100755 --- a/engadd +++ b/engadd @@ -1,4 +1,4 @@ #!/bin/sh # Garbage script to add obscure words to file -echo "$1" >> "$HOME"/langs/english/obscure_words +echo "$1" >>"$HOME"/langs/english/obscure_words diff --git a/inpath b/inpath index 177bb3b..a28ab10 100755 --- a/inpath +++ b/inpath @@ -2,43 +2,43 @@ # Check if a command is in PATH in_path() { - cmd=$1 path=$2 res=1 - IFS=":" + cmd=$1 path=$2 res=1 + IFS=":" - for dir in $path; do - if [ -x "$dir/$cmd" ]; then - res=0 - break - fi - done + for dir in $path; do + if [ -x "$dir/$cmd" ]; then + res=0 + break + fi + done - return $res + return $res } cmd_in_path() { - var=$1 - - if [ -n "$var" ]; then - if [ "$(echo "$var" | cut -c 1)" = "/" ]; then - if [ ! -x "$var" ]; then - return 1 - fi - elif ! in_path "$var" "$PATH"; then - return 2 - fi - fi + var=$1 + + if [ -n "$var" ]; then + if [ "$(echo "$var" | cut -c 1)" = "/" ]; then + if [ ! -x "$var" ]; then + return 1 + fi + elif ! in_path "$var" "$PATH"; then + return 2 + fi + fi } if [ $# -ne 1 ]; then - echo "Usage: $0 " >&2 - exit 1 + echo "Usage: $0 " >&2 + exit 1 fi cmd_in_path "$1" case $? in - 0) echo "$1 found in PATH" ;; - 1) echo "$1 not found or not executable" ;; - 2) echo "$1 not found in PATH" ;; +0) echo "$1 found in PATH" ;; +1) echo "$1 not found or not executable" ;; +2) echo "$1 not found in PATH" ;; esac exit 0 diff --git a/logrm b/logrm index 4bc7d76..045601b 100755 --- a/logrm +++ b/logrm @@ -4,14 +4,14 @@ removelog="/var/log/remove.log" if [ $# -eq 0 ]; then - echo "Usage: $0 [-s] list of files or directories" >&2 - exit 1 + echo "Usage: $0 [-s] list of files or directories" >&2 + exit 1 fi if [ "$1" = "-s" ]; then - shift + shift else - echo "$(date): ${USER}: $*" >>$removelog + echo "$(date): ${USER}: $*" >>$removelog fi rm -i "$@" diff --git a/lsn b/lsn index f6effe0..8f64ae4 100755 --- a/lsn +++ b/lsn @@ -3,7 +3,7 @@ # TODO: fix simlinks, flags break them for some reason, maybe switch to eza ls_new() { - LC_ALL=C $(which ls) -lAFh --color=always "$1" | awk '{ + LC_ALL=C $(which ls) -lAFh --color=always "$1" | awk '{ name = $9; for (i = 10; i <= NF; i++) name = name " " $i; print $1, $5, name diff --git a/maimpick b/maimpick index b8eb9b1..d4d419d 100755 --- a/maimpick +++ b/maimpick @@ -7,7 +7,7 @@ xclip_cmd="xclip -sel clip -t image/png" ocr_cmd="xclip -sel clip" case "$(printf 'a selected area\ncurrent window\nfull screen\na selected area (copy)\ncurrent window (copy)\nfull screen (copy)\ncopy selected image to text' | dmenu -l 7 -i -p "Screenshot which area?")" in - "a selected area") maim -u -s pic-selected-"${output}" ;; +"a selected area") maim -u -s pic-selected-"${output}" ;; "current window") maim -B -q -d 0.2 -i "$(xdotool getactivewindow)" pic-window-"${output}" ;; "full screen") maim -q -d 0.2 pic-full-"${output}" ;; "a selected area (copy)") maim -u -s | ${xclip_cmd} ;; diff --git a/mansplain b/mansplain index aceefcb..43f2ef6 100755 --- a/mansplain +++ b/mansplain @@ -1,5 +1,5 @@ #!/bin/sh # Choose a man manual in dwm and open it in zathura -arg="$( man -k . | dmenu -l 15 | awk '{print $1}')" +arg="$(man -k . | dmenu -l 15 | awk '{print $1}')" [ -n "$arg" ] && man -Tpdf "$arg" | zathura - diff --git a/mounter b/mounter index af1d23b..121540b 100755 --- a/mounter +++ b/mounter @@ -8,7 +8,7 @@ IFS=' ' # Function for escaping cell-phone names. -escape(){ echo "$@" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g" ;} +escape() { echo "$@" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g"; } # Check for phones. phones="$(simple-mtpfs -l 2>/dev/null | sed "s/^/📱/")" @@ -17,7 +17,7 @@ mountedphones="$(grep "simple-mtpfs" /etc/mtab)" [ -n "$mountedphones" ] && phones="$(for phone in $phones; do for mounted in $mountedphones; do escphone="$(escape "$phone")" - [[ "$mounted" =~ "$escphone" ]] && break 1 + [[ $mounted =~ $escphone ]] && break 1 done && continue 1 echo "$phone" done)" @@ -29,12 +29,12 @@ allluks="$(echo "$lsblkoutput" | grep crypto_LUKS)" # Get a list of the LUKS drive UUIDs already decrypted. decrypted="$(find /dev/disk/by-id/dm-uuid-CRYPT-LUKS2-* | sed "s|.*LUKS2-||;s|-.*||")" # Functioning for formatting drives correctly for dmenu: -filter() { sed "s/ /:/g" | awk -F':' '$7==""{printf "%s%s (%s) %s\n",$1,$3,$5,$6}' ; } +filter() { sed "s/ /:/g" | awk -F':' '$7==""{printf "%s%s (%s) %s\n",$1,$3,$5,$6}'; } # Get only LUKS drives that are not decrypted. unopenedluks="$(for drive in $allluks; do uuid="${drive%% *}" - uuid="${uuid//-}" # This is a bashism. + uuid="${uuid//-/}" # This is a bashism. [ -n "$decrypted" ] && for open in $decrypted; do [ "$uuid" = "$open" ] && break 1 done && continue 1 @@ -42,7 +42,7 @@ unopenedluks="$(for drive in $allluks; do done | filter)" # Get all normal, non-encrypted or decrypted partitions that are not mounted. -normalparts="$(echo "$lsblkoutput"| grep -v crypto_LUKS | grep 'part\|rom\|crypt' | sed "s/^/💾 /" | filter )" +normalparts="$(echo "$lsblkoutput" | grep -v crypto_LUKS | grep 'part\|rom\|crypt' | sed "s/^/💾 /" | filter)" # Add all to one variable. If no mountable drives found, exit. alldrives="$(echo "$phones @@ -58,61 +58,61 @@ test -n "$alldrives" chosen="$(echo "$alldrives" | dmenu -p "Mount which drive?" -i)" # Function for prompting user for a mountpoint. -getmount(){ - mp="$(find /mnt /media /mount /home -maxdepth 1 -type d 2>/dev/null | dmenu -i -p "Mount this drive where?")" - test -n "$mp" - if [ ! -d "$mp" ]; then - mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") - [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") - fi +getmount() { + mp="$(find /mnt /media /mount /home -maxdepth 1 -type d 2>/dev/null | dmenu -i -p "Mount this drive where?")" + test -n "$mp" + if [ ! -d "$mp" ]; then + mkdiryn=$(printf 'No\nYes' | dmenu -i -p "$mp does not exist. Create it?") + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + fi } -attemptmount(){ - # Attempt to mount without a mountpoint, to see if drive is in fstab. - sudo -A mount "$chosen" || return 1 - notify-send "💾Drive Mounted." "$chosen mounted." - exit +attemptmount() { + # Attempt to mount without a mountpoint, to see if drive is in fstab. + sudo -A mount "$chosen" || return 1 + notify-send "💾Drive Mounted." "$chosen mounted." + exit } case "$chosen" in - 💾*) - chosen="${chosen%% *}" - chosen="${chosen:1}" # This is a bashism. - parttype="$(echo "$lsblkoutput" | grep "$chosen")" - attemptmount || getmount - case "${parttype##* }" in - vfat) sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000 ;; - btrfs) sudo -A mount "$chosen" "$mp" ;; - *) sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)" ;; - esac - notify-send "💾Drive Mounted." "$chosen mounted to $mp." - ;; - - 🔒*) - chosen="${chosen%% *}" - chosen="${chosen:1}" # This is a bashism. - # Number the drive. - while true; do - [ -f "/dev/mapper/usb$num" ] || break - num="$(printf "%02d" "$((num +1))")" - done - - # Decrypt in a terminal window - ${TERMINAL:-st} -n floatterm -g 60x1 -e sudo cryptsetup open "$chosen" "usb$num" - # Check if now decrypted. - test -b "/dev/mapper/usb$num" - - attemptmount || getmount - sudo -A mount "/dev/mapper/usb$num" "$mp" -o uid="$(id -u)",gid="$(id -g)" - notify-send "🔓Decrypted drive Mounted." "$chosen decrypted and mounted to $mp." - ;; - - 📱*) - notify-send "❗Note" "Remember to allow file access on your phone now." - getmount - number="${chosen%%:*}" - number="${chosen:1}" # This is a bashism. - sudo -A simple-mtpfs -o allow_other -o fsname="simple-mtpfs-$(escape "$chosen")" --device "$number" "$mp" - notify-send "🤖 Android Mounted." "Android device mounted to $mp." - ;; +💾*) + chosen="${chosen%% *}" + chosen="${chosen:1}" # This is a bashism. + parttype="$(echo "$lsblkoutput" | grep "$chosen")" + attemptmount || getmount + case "${parttype##* }" in + vfat) sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000 ;; + btrfs) sudo -A mount "$chosen" "$mp" ;; + *) sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)" ;; + esac + notify-send "💾Drive Mounted." "$chosen mounted to $mp." + ;; + +🔒*) + chosen="${chosen%% *}" + chosen="${chosen:1}" # This is a bashism. + # Number the drive. + while true; do + [ -f "/dev/mapper/usb$num" ] || break + num="$(printf "%02d" "$((num + 1))")" + done + + # Decrypt in a terminal window + ${TERMINAL:-st} -n floatterm -g 60x1 -e sudo cryptsetup open "$chosen" "usb$num" + # Check if now decrypted. + test -b "/dev/mapper/usb$num" + + attemptmount || getmount + sudo -A mount "/dev/mapper/usb$num" "$mp" -o uid="$(id -u)",gid="$(id -g)" + notify-send "🔓Decrypted drive Mounted." "$chosen decrypted and mounted to $mp." + ;; + +📱*) + notify-send "❗Note" "Remember to allow file access on your phone now." + getmount + number="${chosen%%:*}" + number="${chosen:1}" # This is a bashism. + sudo -A simple-mtpfs -o allow_other -o fsname="simple-mtpfs-$(escape "$chosen")" --device "$number" "$mp" + notify-send "🤖 Android Mounted." "Android device mounted to $mp." + ;; esac diff --git a/newnote b/newnote index e0bd2a3..d9f85cc 100755 --- a/newnote +++ b/newnote @@ -4,20 +4,20 @@ dir="$OBSIDIAN_HOME" newnote() { - file="$dir/$1.md" - [ -f "$file" ] && { - echo "Note with the same name already exists, exiting" >&2 - exit 1 - } - touch "$file" && "$EDITOR" +2 "$file" - if [ "$(wc -l "$file" | awk '{print $1}')" -lt 2 ]; then - rm -f "$file" - fi + file="$dir/$1.md" + [ -f "$file" ] && { + echo "Note with the same name already exists, exiting" >&2 + exit 1 + } + touch "$file" && "$EDITOR" +2 "$file" + if [ "$(wc -l "$file" | awk '{print $1}')" -lt 2 ]; then + rm -f "$file" + fi } [ "$#" -ne 1 ] && { - echo "Usage: newnote " >&2 - exit 1 + echo "Usage: newnote " >&2 + exit 1 } newnote "$1" diff --git a/newscript b/newscript index 87220ba..da2a21a 100755 --- a/newscript +++ b/newscript @@ -2,22 +2,22 @@ # Add a new script newscript() { - file="$HOME/.scripts/$1" - [ -f "$file" ] && { - echo "Script with the same name already exists, exiting" >&2 - exit 1 - } - touch "$file" && printf "#!/bin/sh\n\n" >"$file" && "$EDITOR" +2 "$file" - if [ "$(wc -l "$file" | awk '{print $1}')" -lt 3 ]; then - rm -f "$file" - else - chmod +x "$file" - fi + file="$HOME/.scripts/$1" + [ -f "$file" ] && { + echo "Script with the same name already exists, exiting" >&2 + exit 1 + } + touch "$file" && printf "#!/bin/sh\n\n" >"$file" && "$EDITOR" +2 "$file" + if [ "$(wc -l "$file" | awk '{print $1}')" -lt 3 ]; then + rm -f "$file" + else + chmod +x "$file" + fi } [ "$#" -ne 1 ] && { - echo "Usage: newscript " >&2 - exit 1 + echo "Usage: newscript " >&2 + exit 1 } newscript "$1" diff --git a/notesplain b/notesplain index 80b057b..c263757 100755 --- a/notesplain +++ b/notesplain @@ -5,6 +5,6 @@ dir="$OBSIDIAN_HOME" file="$(ls -1 "$dir" | sed 's/\.md$//' | dmenu -l 15 -p 'Select note:')" if [ -n "$file" ]; then - tmpfile="$(mktemp /tmp/"$file"_XXXXXXXX.pdf)" - pandoc "$dir/$file.md" -o "$tmpfile" && zathura "$tmpfile" & + tmpfile="$(mktemp /tmp/"$file"_XXXXXXXX.pdf)" + pandoc "$dir/$file.md" -o "$tmpfile" && zathura "$tmpfile" & fi diff --git a/printpath b/printpath index 396fd86..a76f8f9 100755 --- a/printpath +++ b/printpath @@ -2,6 +2,6 @@ # Print everythin in PATH echo "$PATH" | tr ':' '\n' | while IFS= read -r dir; do - [ -d "$dir" ] || continue - find "$dir" -maxdepth 1 -type f -perm -111 -printf '%f\n' + [ -d "$dir" ] || continue + find "$dir" -maxdepth 1 -type f -perm -111 -printf '%f\n' done | sort -u diff --git a/rmw b/rmw index 6bd558d..37a2504 100755 --- a/rmw +++ b/rmw @@ -2,24 +2,24 @@ # Remove whitespaces in all the files in a given directory if [ "$#" -gt 1 ]; then - echo "Usage: rmw " >&2 - exit 1 + echo "Usage: rmw " >&2 + exit 1 fi if [ "$#" -eq 0 ]; then - dir="$(pwd)" + dir="$(pwd)" else - dir="$1" + dir="$1" fi cd "$dir" || { - echo "Couldn't cd to directory. Exiting..." >&2 - exit 1 + echo "Couldn't cd to directory. Exiting..." >&2 + exit 1 } for file in "$dir"/*; do - newname="$(echo "$file" | sed -e 's/["`”“-]*//g' -e 's/[ \t]+/\_/g')" - mv "$file" "$newname" + newname="$(echo "$file" | sed -e 's/["`”“-]*//g' -e 's/[ \t]+/\_/g')" + mv "$file" "$newname" done exit 0 diff --git a/rssadd b/rssadd index 86087f0..00e9c9d 100755 --- a/rssadd +++ b/rssadd @@ -2,9 +2,9 @@ # Add a new RSS feed if echo "$1" | grep -q "https*://\S\+\.[A-Za-z]\+\S*"; then - url="$1" + url="$1" else - url="$(grep -Eom1 '<[^>]+(rel="self"|application/[a-z]+\+xml)[^>]+>' "$1" | + url="$(grep -Eom1 '<[^>]+(rel="self"|application/[a-z]+\+xml)[^>]+>' "$1" | grep -o 'https?://[^" ]')" echo "$url" | grep -q "https*://\S\+\.[A-Za-z]\+\S*" || diff --git a/rssget b/rssget index 10fbbf0..73fb25e 100755 --- a/rssget +++ b/rssget @@ -12,21 +12,21 @@ # This script requires rssadd to add feeds to the list. -getlink () { - local url="$1" - feeds="$(curl -s "$url" | grep -Ex '.*type=.*(rss|rdf|atom).*' | sed 's/ //g')" - url="$(echo $url | sed 's|^\(https://[^/]*/\).*|\1|')" - - for rsspath in $feeds; do - rsspath="$(echo $rsspath | sed -n "s|.*href=['\"]\([^'\"]*\)['\"].*|\1|p")" - if echo "$rsspath" | grep "http" > /dev/null; then - link="$rsspath" - elif echo "$rsspath" | grep -E "^/" > /dev/null; then - link="$url$(echo $rsspath | sed 's|^/||')" - else - link="$url$rsspath" - fi - echo $link +getlink() { + local url="$1" + feeds="$(curl -s "$url" | grep -Ex '.*type=.*(rss|rdf|atom).*' | sed 's/ //g')" + url="$(echo $url | sed 's|^\(https://[^/]*/\).*|\1|')" + + for rsspath in $feeds; do + rsspath="$(echo $rsspath | sed -n "s|.*href=['\"]\([^'\"]*\)['\"].*|\1|p")" + if echo "$rsspath" | grep "http" >/dev/null; then + link="$rsspath" + elif echo "$rsspath" | grep -E "^/" >/dev/null; then + link="$url$(echo $rsspath | sed 's|^/||')" + else + link="$url$rsspath" + fi + echo $link done } @@ -38,48 +38,48 @@ getYoutubeRss() { local url="$1" path=$(echo "$url" | sed -e 's|^http[s]*://||') case "$path" in - *"/channel/"*) channel_id="$(echo $path | sed -r 's|.*channel/([^/]*).*|\1|')" && feed="https://www.youtube.com/feeds/videos.xml?channel_id=${channel_id}" ;; - *"/c/"*|*"/user/"*) - feed=$(wget -q "$url" -O tmp_rssget_yt \ - && sed -n 's|.*\("rssUrl":"[^"]*\).*|\1|; p' tmp_rssget_yt \ - | grep rssUrl \ - | sed 's|"rssUrl":"||') ;; + *"/channel/"*) channel_id="$(echo $path | sed -r 's|.*channel/([^/]*).*|\1|')" && feed="https://www.youtube.com/feeds/videos.xml?channel_id=${channel_id}" ;; + *"/c/"* | *"/user/"*) + feed=$(wget -q "$url" -O tmp_rssget_yt && + sed -n 's|.*\("rssUrl":"[^"]*\).*|\1|; p' tmp_rssget_yt | + grep rssUrl | + sed 's|"rssUrl":"||') + ;; esac echo "$feed" } getVimeoRss() { - local url="$1" - if echo "$url" | grep -q "/videos$"; then - feed_url=$(echo "$url" | sed 's/\/videos$//' | sed 's/\/$/\/rss/') - else - feed_url="${url}/videos/rss" - fi - echo "$feed_url" + local url="$1" + if echo "$url" | grep -q "/videos$"; then + feed_url=$(echo "$url" | sed 's/\/videos$//' | sed 's/\/$/\/rss/') + else + feed_url="${url}/videos/rss" + fi + echo "$feed_url" } -getGithubRss () { +getGithubRss() { local url="${1%/}" - if echo $url | grep -E "github.com/[^/]*/[a-zA-Z0-9].*" >/dev/null ; then + if echo $url | grep -E "github.com/[^/]*/[a-zA-Z0-9].*" >/dev/null; then echo "${url}/commits.atom" echo "${url}/releases.atom" echo "${url}/tags.atom" - elif echo $url | grep -E "github.com/[^/]*(/)" >/dev/null ; then + elif echo $url | grep -E "github.com/[^/]*(/)" >/dev/null; then echo "${url}.atom" fi } -getGitlabRss () { +getGitlabRss() { local url="${1%/}" echo "${url}.atom" } -getMediumRss () { +getMediumRss() { echo $1 | sed 's|/tag/|/feed/|' } - -if [ -n "$1" ] ; then +if [ -n "$1" ]; then url="$1" else url="$(xclip -selection clipboard -o)" @@ -91,19 +91,19 @@ declare -a list=() yt_regex="^(http(s)?://)?((w){3}\.)?(youtube\.com|invidio\.us|invidious\.flokinet\.to|invidious\.materialio\.us|iv\.datura\.network|invidious\.perennialte\.ch|invidious\.fdn\.fr|invidious\.private\.coffee|invidious\.protokolla\.fi|invidious\.privacyredirect\.com|yt\.artemislena\.eu|yt\.drgnz\.club|invidious\.incogniweb\.net|yewtu\.be|inv\.tux\.pizza|invidious\.reallyaweso\.me|iv\.melmac\.space|inv\.us\.projectsegfau\.lt|inv\.nadeko\.net|invidious\.darkness\.services|invidious\.jing\.rocks|invidious\.privacydev\.net|inv\.in\.projectsegfau\.lt|invidious\.drgns\.space)/(channel|user|c).+" reddit_regex="^(http(s)?://)?((w){3}\.)?reddit\.com.*" vimeo_regex="^(http(s)?://)?((w){3}.)?vimeo\.com.*" -if echo $url | grep -Ex "$yt_regex" >/dev/null ; then +if echo $url | grep -Ex "$yt_regex" >/dev/null; then list="$(getYoutubeRss "$url")" -elif echo $url | grep -Ex "$reddit_regex" >/dev/null ; then +elif echo $url | grep -Ex "$reddit_regex" >/dev/null; then list="$(getRedditRss "$url")" # vimeo actually works with getlink -elif echo $url | grep -E "$vimeo_regex" >/dev/null ; then +elif echo $url | grep -E "$vimeo_regex" >/dev/null; then list="$(getVimeoRss "$url")" -elif echo $url | grep -E "github.com" >/dev/null ; then +elif echo $url | grep -E "github.com" >/dev/null; then list="$(getGithubRss "$url")" # gitlab also works with getlink -elif echo $url | grep -E "gitlab.com/[a-zA-Z0-9].*" >/dev/null ; then +elif echo $url | grep -E "gitlab.com/[a-zA-Z0-9].*" >/dev/null; then list="$(getGitlabRss "$url")" -elif echo $url | grep -E "medium.com/tag" >/dev/null ; then +elif echo $url | grep -E "medium.com/tag" >/dev/null; then list="$(getMediumRss "$url")" else list="$(getlink "$url")" @@ -111,7 +111,7 @@ fi [ "$(echo "$list" | wc -l)" -eq 1 ] && chosen_link="$list" || chosen_link=$(printf '%s\n' "${list[@]}" | dmenu -p "Choose a feed:") tags="$2" -if which rssadd; - then rssadd "$chosen_link" "$tags" +if which rssadd; then + rssadd "$chosen_link" "$tags" fi echo "$chosen_link" "$tags" diff --git a/saferm b/saferm index c27b143..ca49554 100755 --- a/saferm +++ b/saferm @@ -5,33 +5,33 @@ realrm="$(which rm)" copy="$(which cp) -R" if [ $# -eq 0 ]; then - exec $realrm + exec $realrm fi flags="" while getopts "dfiPRrvW" opt; do - case $opt in - f) exec $realrm "$@" ;; - *) flags="$flags -$opt" ;; - esac + case $opt in + f) exec $realrm "$@" ;; + *) flags="$flags -$opt" ;; + esac done shift $((OPTIND - 1)) if [ ! -d "$archive" ]; then - if [ ! -w "$HOME" ]; then - echo "$0 failed: can't create $archive in $HOME" >&2 - exit 1 - fi - mkdir "$archive" - chmod 700 "$archive" + if [ ! -w "$HOME" ]; then + echo "$0 failed: can't create $archive in $HOME" >&2 + exit 1 + fi + mkdir "$archive" + chmod 700 "$archive" fi for arg; do - newname="$archive/$(date "+%S.%M.%H.%d.%m").$(basename "$arg")" - if [ -f "$arg" ] || [ -d "$arg" ]; then - $copy "$arg" "$newname" - fi + newname="$archive/$(date "+%S.%M.%H.%d.%m").$(basename "$arg")" + if [ -f "$arg" ] || [ -d "$arg" ]; then + $copy "$arg" "$newname" + fi done exec $realrm "$flags" "$@" diff --git a/scan b/scan index c152090..55a42ab 100755 --- a/scan +++ b/scan @@ -5,7 +5,7 @@ file=$(find . -mindepth 2 -type f 2>/dev/null | sed 's|^\./||' | sort | dmenu -l # If a file was selected if [ -n "$file" ]; then - echo "You selected: $file" - # Do something with the selected file here, like open it: - # xdg-open "$file" # Uncomment if desired + echo "You selected: $file" + # Do something with the selected file here, like open it: + # xdg-open "$file" # Uncomment if desired fi diff --git a/sysact b/sysact index 57672f4..53a7cb9 100755 --- a/sysact +++ b/sysact @@ -3,34 +3,34 @@ # A dmenu wrapper script for system functions. export WM="dwm" case "$(readlink -f /sbin/init)" in - *systemd*) ctl='systemctl' ;; - *) ctl='loginctl' ;; +*systemd*) ctl='systemctl' ;; +*) ctl='loginctl' ;; esac -wmpid(){ # This function is needed if there are multiple instances of the window manager. - tree="$(pstree -ps $$)" - tree="${tree#*$WM(}" - echo "${tree%%)*}" +wmpid() { # This function is needed if there are multiple instances of the window manager. + tree="$(pstree -ps $$)" + tree="${tree#*$WM(}" + echo "${tree%%)*}" } -lock(){ - mpc pause - pauseallmpv - wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle - kill -44 $(pidof dwmblocks) - slock - wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle - kill -44 $(pidof dwmblocks) +lock() { + mpc pause + pauseallmpv + wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle + kill -44 $(pidof dwmblocks) + slock + wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle + kill -44 $(pidof dwmblocks) } case "$(printf "🔒 lock\n🚪 leave $WM\n♻️ renew $WM\n🐻 hibernate\n🔃 reboot\n🖥️shutdown\n💤 sleep\n📺 display off" | dmenu -i -p 'Action: ')" in - '🔒 lock') lock ;; - "🚪 leave $WM") kill -TERM "$(wmpid)" ;; - "♻️ renew $WM") kill -HUP "$(wmpid)" ;; - '🐻 hibernate') slock $ctl hibernate -i ;; - '💤 sleep') slock $ctl suspend -i ;; - '🔃 reboot') $ctl reboot -i ;; - '🖥️shutdown') $ctl poweroff -i ;; - '📺 display off') xset dpms force off ;; - *) exit 1 ;; +'🔒 lock') lock ;; +"🚪 leave $WM") kill -TERM "$(wmpid)" ;; +"♻️ renew $WM") kill -HUP "$(wmpid)" ;; +'🐻 hibernate') slock $ctl hibernate -i ;; +'💤 sleep') slock $ctl suspend -i ;; +'🔃 reboot') $ctl reboot -i ;; +'🖥️shutdown') $ctl poweroff -i ;; +'📺 display off') xset dpms force off ;; +*) exit 1 ;; esac diff --git a/todo b/todo index 06fa01f..cba0126 100755 --- a/todo +++ b/todo @@ -10,18 +10,18 @@ touch "$file" height="$(wc -l "$file" | awk '{print $1}')" prompt="Add/delete a task: " -cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file") +cmd=$(dmenu -l "$height" -p "$prompt" "$@" <"$file") while [ -n "$cmd" ]; do - if grep -q "^$cmd\$" "$file"; then - grep -v "^$cmd\$" "$file" > "$file.$$" - mv "$file.$$" "$file" - height=$(( height - 1 )) - else - echo "$cmd" >> "$file" - height=$(( height + 1 )) - fi + if grep -q "^$cmd\$" "$file"; then + grep -v "^$cmd\$" "$file" >"$file.$$" + mv "$file.$$" "$file" + height=$((height - 1)) + else + echo "$cmd" >>"$file" + height=$((height + 1)) + fi - cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file") + cmd=$(dmenu -l "$height" -p "$prompt" "$@" <"$file") done exit 0 diff --git a/via b/via index 75f19ef..4a96040 100755 --- a/via +++ b/via @@ -3,13 +3,13 @@ PATH="$HOME/.config/via:$PATH" case "$1" in - -r) # rebuild cache first - via-feed -r | via-menu | via-open - ;; - -ro) # rebuild cache only - via-feed -r >/dev/null - ;; - *) - via-feed | via-menu | via-open - ;; +-r) # rebuild cache first + via-feed -r | via-menu | via-open + ;; +-ro) # rebuild cache only + via-feed -r >/dev/null + ;; +*) + via-feed | via-menu | via-open + ;; esac diff --git a/via-feed b/via-feed index d0d2544..af78b17 100755 --- a/via-feed +++ b/via-feed @@ -2,23 +2,23 @@ cache="$HOME/.cache/via" -if [[ "$1" == "-r" ]] || [[ ! -e "$cache" ]]; then - cat "$HOME/.config/via/shortcuts" > "$cache" - cat "$HOME/.config/via/websites" >> "$cache" - find "$HOME" -mindepth 1 \ - \( \ - -type d -name ".*" ! -path "$HOME/.scripts" \ - -o -path "$HOME/cell" \ - -o -path "$HOME/phone/*" \ - \) -prune \ - -o -print \ - | sort >> "$cache" - # notify-send "via cache updated." +if [[ $1 == "-r" ]] || [[ ! -e $cache ]]; then + cat "$HOME/.config/via/shortcuts" >"$cache" + cat "$HOME/.config/via/websites" >>"$cache" + find "$HOME" -mindepth 1 \ + \( \ + -type d -name ".*" ! -path "$HOME/.scripts" \ + -o -path "$HOME/cell" \ + -o -path "$HOME/phone/*" \ + \) -prune \ + -o -print | + sort >>"$cache" + # notify-send "via cache updated." fi if [ "$CRON" = "1" ]; then - exit 0 + exit 0 else - wmctrl -xl | sed "s/^[^.]*\.//;s/ \+\S\+ \+/ /;s/^/w /;s/ \+/ /g" - cat "$cache" + wmctrl -xl | sed "s/^[^.]*\.//;s/ \+\S\+ \+/ /;s/^/w /;s/ \+/ /g" + cat "$cache" fi diff --git a/via-open b/via-open index 14bfb35..0ed23c0 100755 --- a/via-open +++ b/via-open @@ -1,56 +1,56 @@ #!/bin/bash -exec &> /dev/null +exec &>/dev/null while read -r arg; do - # first try matching by filename or pathname - case "${arg,,}" in - w\ *) - target=$(echo "$arg"|cut -d ' ' -f 3-) - wmctrl -a "$target" - ;; - http*) - $BROWSER "$arg" & - ;; - [^/]*) # doesn't start with '/' - sh -c "$arg" - ;; - *.txt) - # tabbed -c -r 2 $TERMINAL -w '' -e $EDITOR "$arg" & - $TERMINAL $EDITOR "$arg" & - ;; - *.pdf | *.epub) - zathura "$arg" & - ;; - *.mp3) - $TERMINAL mpg123 -opulse "$arg" & - ;; - *.od[tsp]|*.doc|*.docx|*.ppt|*.pptx|*.xls|*.xlsx) - libreoffice "$arg" & - ;; - *) - # then try matching by mimetype - mimetype=$(file -Lb --mime-type "$arg") - case "$mimetype" in - text/html) - $BROWSER "$arg" & - ;; - text/* | inode/x-empty | message/rfc822) - # tabbed -c -r 2 $TERMINAL -w '' -e $EDITOR "$arg" & - $TERMINAL $EDITOR "$arg" & - ;; - inode/directory) - cd "$arg" || exit - $TERMINAL & - cd - || exit - ;; - image/*) - sxiv "$arg" & - ;; - *) - $TERMINAL $EDITOR "$arg" & - ;; - esac - ;; - esac + # first try matching by filename or pathname + case "${arg,,}" in + w\ *) + target=$(echo "$arg" | cut -d ' ' -f 3-) + wmctrl -a "$target" + ;; + http*) + $BROWSER "$arg" & + ;; + [^/]*) # doesn't start with '/' + sh -c "$arg" + ;; + *.txt) + # tabbed -c -r 2 $TERMINAL -w '' -e $EDITOR "$arg" & + $TERMINAL $EDITOR "$arg" & + ;; + *.pdf | *.epub) + zathura "$arg" & + ;; + *.mp3) + $TERMINAL mpg123 -opulse "$arg" & + ;; + *.od[tsp] | *.doc | *.docx | *.ppt | *.pptx | *.xls | *.xlsx) + libreoffice "$arg" & + ;; + *) + # then try matching by mimetype + mimetype=$(file -Lb --mime-type "$arg") + case "$mimetype" in + text/html) + $BROWSER "$arg" & + ;; + text/* | inode/x-empty | message/rfc822) + # tabbed -c -r 2 $TERMINAL -w '' -e $EDITOR "$arg" & + $TERMINAL $EDITOR "$arg" & + ;; + inode/directory) + cd "$arg" || exit + $TERMINAL & + cd - || exit + ;; + image/*) + sxiv "$arg" & + ;; + *) + $TERMINAL $EDITOR "$arg" & + ;; + esac + ;; + esac done diff --git a/volume b/volume index 7047805..f2a3e4b 100755 --- a/volume +++ b/volume @@ -2,8 +2,8 @@ # TODO: see if pulseaudio is running case "$1" in - up) pactl set-sink-volume @DEFAULT_SINK@ "+5%" && notify-send "Volume increased by 5%" ;; - down) pactl set-sink-volume @DEFAULT_SINK@ "-5%" && notify-send "Volume decreased by 5%" ;; - mute) pactl set-sink-mute @DEFAULT_SINK@ toggle && notify-send "Volume muted/unmuted" ;; - *) pactl set-sink-volume @DEFAULT_SINK@ "$1" && notify-send "Volume increased by $1%" ;; +up) pactl set-sink-volume @DEFAULT_SINK@ "+5%" && notify-send "Volume increased by 5%" ;; +down) pactl set-sink-volume @DEFAULT_SINK@ "-5%" && notify-send "Volume decreased by 5%" ;; +mute) pactl set-sink-mute @DEFAULT_SINK@ toggle && notify-send "Volume muted/unmuted" ;; +*) pactl set-sink-volume @DEFAULT_SINK@ "$1" && notify-send "Volume increased by $1%" ;; esac diff --git a/wrocwttr b/wrocwttr index dccb1cc..727a464 100755 --- a/wrocwttr +++ b/wrocwttr @@ -8,7 +8,7 @@ FILE="$CACHE_DIR/wroc.txt" mkdir -p "$CACHE_DIR" temp="$(curl -fsS --max-time 5 -A "wrocwttr/1.0" \ - "https://wttr.in/$CITY?format=%t")" || exit 1 + "https://wttr.in/$CITY?format=%t")" || exit 1 [ -z "$temp" ] && exit 1 -echo "$temp" > "$FILE" +echo "$temp" >"$FILE" -- cgit v1.2.3