diff options
author | filip <“filip.rabiega@gmail.com”> | 2025-10-10 19:10:02 +0200 |
---|---|---|
committer | filip <“filip.rabiega@gmail.com”> | 2025-10-10 19:10:02 +0200 |
commit | 807de46d3a3cbef9a3c3c104f6db87b142e6eed5 (patch) | |
tree | 61a1a9bc26daad623ce6c04bb66ae39133ef0261 | |
parent | 08204fc9b9f63015a1dc083b471c6839818eeb59 (diff) | |
download | chadscripts-807de46d3a3cbef9a3c3c104f6db87b142e6eed5.tar.gz chadscripts-807de46d3a3cbef9a3c3c104f6db87b142e6eed5.tar.bz2 chadscripts-807de46d3a3cbef9a3c3c104f6db87b142e6eed5.zip |
used shfmt
-rwxr-xr-x | buku-dmenu | 8 | ||||
-rwxr-xr-x | chadsearch | 3 | ||||
-rwxr-xr-x | decperc | 46 | ||||
-rwxr-xr-x | dictloop | 19 | ||||
-rwxr-xr-x | es | 2 | ||||
-rwxr-xr-x | extract_pdfs | 37 | ||||
-rwxr-xr-x | inpath | 59 | ||||
-rwxr-xr-x | launch | 8 | ||||
-rwxr-xr-x | logrm | 8 | ||||
-rwxr-xr-x | lsn | 6 | ||||
-rwxr-xr-x | maimpick | 14 | ||||
-rwxr-xr-x | newnote | 22 | ||||
-rwxr-xr-x | newscript | 26 | ||||
-rwxr-xr-x | printpath | 8 | ||||
-rwxr-xr-x | remaps | 3 | ||||
-rwxr-xr-x | rm_whitespaces | 17 | ||||
-rwxr-xr-x | rssadd | 4 | ||||
-rwxr-xr-x | saferm | 38 | ||||
-rwxr-xr-x | scan | 6 |
19 files changed, 172 insertions, 162 deletions
@@ -1,9 +1,9 @@ #!/bin/bash -if [ "$1" == "--help" ] ; then - echo "Run the script, start typing until the desired bookmark is selected." - echo "buku and dmenu must be installed." - return 1 +if [ "$1" == "--help" ]; then + echo "Run the script, start typing until the desired bookmark is selected." + echo "buku and dmenu must be installed." + return 1 fi # get all bmks | swap tabs for spaces | run dmenu | cut to ID | run buku if not empty diff --git a/chadsearch b/chadsearch deleted file mode 100755 index 852205d..0000000 --- a/chadsearch +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -librewolf --new-window --search "$1" @@ -1,30 +1,30 @@ #!/usr/bin/zsh -dec_into_perc () { - dec="$1" - # duplicating code, don't care - if echo "$dec" | grep -qE '^(-?[0-9]+\.[0-9]+|-?[0-9]|\.[0-9]+)$'; then - percent="$( echo "$dec * 100" | bc -l )" - echo "${percent}%" - else - echo "Error: not a decimal number" >&2 - exit 1 - fi +dec_into_perc() { + dec="$1" + # duplicating code, don't care + if echo "$dec" | grep -qE '^(-?[0-9]+\.[0-9]+|-?[0-9]|\.[0-9]+)$'; then + percent="$(echo "$dec * 100" | bc -l)" + echo "${percent}%" + else + echo "Error: not a decimal number" >&2 + exit 1 + fi } -perc_into_dec () { - perc="$1" - # duplicating code, don't care - if echo "$perc" | grep -qE '^(-?[0-9]+\.[0-9]+%|-?[0-9]+%|\.[0-9]+%)$'; then - dec="{$perc%?}" - dec="$( echo "$dec / 100" | bc -l )" - echo "$dec" - else - echo "Error: not a percent" >&2 - exit 1 - fi +perc_into_dec() { + perc="$1" + # duplicating code, don't care + if echo "$perc" | grep -qE '^(-?[0-9]+\.[0-9]+%|-?[0-9]+%|\.[0-9]+%)$'; then + dec="{$perc%?}" + dec="$(echo "$dec / 100" | bc -l)" + echo "$dec" + else + echo "Error: not a percent" >&2 + exit 1 + fi } echo "$1" | grep -qE '^(-?[0-9]+\.[0-9]+|-?[0-9]|\.[0-9]+|-?[0-9]+\.[0-9]+%|-?[0-9]+%|\.[0-9]+%)$' && - len=${#1} && - [[ "${1:len-1:1}" == "%" ]] && perc_into_dec "$1" || dec_into_perc "$1" + len=${#1} && + [[ "${1:len-1:1}" == "%" ]] && perc_into_dec "$1" || dec_into_perc "$1" @@ -3,19 +3,22 @@ setopt aliases source "$ZDOTDIR/aliasrc" -[ "$#" -ne 1 ] && { echo "Usage: dictloop <dict>" >&2; exit 1; } +[ "$#" -ne 1 ] && { + echo "Usage: dictloop <dict>" >&2 + exit 1 +} dict="$1" # a command-line dictionary while true; do - echo "Enter a word: " - read -r word + echo "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 exit 0 @@ -1,4 +1,4 @@ #!/bin/sh -file="$SCRIPTS/$( /bin/ls "$SCRIPTS" | sed 's/[\s]+/ /g' | dmenu -l 15 -i -p "Choose a script to edit: " )" +file="$SCRIPTS/$(/bin/ls "$SCRIPTS" | sed 's/[\s]+/ /g' | dmenu -l 15 -i -p "Choose a script to edit: ")" [ -f "$file" ] && vim "$file" diff --git a/extract_pdfs b/extract_pdfs index 96e2ce7..2fb0d49 100755 --- a/extract_pdfs +++ b/extract_pdfs @@ -1,36 +1,33 @@ #!/usr/bin/zsh if [ "$#" -ne 2 ]; then - echo "Usage: extract_pdfs /path/to/source /path/to/destination" - exit 1 + echo "Usage: extract_pdfs /path/to/source /path/to/destination" + exit 1 fi SOURCE_DIR="$1" DEST_DIR="$2" - if [ ! -d "$SOURCE_DIR" ]; then - echo "Source directory does not exist: $SOURCE_DIR" - exit 1 + notify-send "Source directory does not exist: $SOURCE_DIR" + exit 1 fi - mkdir -p "$DEST_DIR" - find "$SOURCE_DIR" -type f -iname "*.pdf" | while read -r pdf; do - filename=$(basename "$pdf") - - dest_file="$DEST_DIR/$filename" - if [ -e "$dest_file" ]; then - i=1 - while [ -e "$DEST_DIR/${filename%.*}_$i.pdf" ]; do - ((i++)) - done - dest_file="$DEST_DIR/${filename%.*}_$i.pdf" - fi - - cp "$pdf" "$dest_file" + filename=$(basename "$pdf") + + dest_file="$DEST_DIR/$filename" + if [ -e "$dest_file" ]; then + i=1 + while [ -e "$DEST_DIR/${filename%.*}_$i.pdf" ]; do + ((i++)) + done + dest_file="$DEST_DIR/${filename%.*}_$i.pdf" + fi + + cp "$pdf" "$dest_file" done -echo "PDF extraction complete. Files copied to: $DEST_DIR" +notify-send "PDF extraction complete. Files copied to: $DEST_DIR" @@ -1,44 +1,43 @@ #!/bin/sh -in_path () { - cmd=$1 path=$2 res=1 - IFS=":" - - for dir in $path; - do - if [ -x "$dir/$cmd" ]; then - res=0 - break - fi - done - - return $res +in_path() { + cmd=$1 path=$2 res=1 + IFS=":" + + for dir in $path; do + if [ -x "$dir/$cmd" ]; then + res=0 + break + fi + done + + 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 +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 } if [ $# -ne 1 ]; then - echo "Usage: $0 <command>" >&2 - exit 1 + echo "Usage: $0 <command>" >&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 @@ -3,12 +3,12 @@ launch_list="$HOME/.config/launch.list" if [ ! -r "$launch_list" ]; then - notify-send "Launcher Error" "Program list not found: $launch_list" - exit 1 + notify-send "Launcher Error" "Program list not found: $launch_list" + exit 1 fi -prog="$( dmenu -l 30 -i -p "Choose a program to launch:" < "$launch_list" )" +prog="$(dmenu -l 30 -i -p "Choose a program to launch:" <"$launch_list")" [ -z "$prog" ] && exit 0 -setsid "$prog" > /dev/null 2>&1 & +setsid "$prog" >/dev/null 2>&1 & @@ -3,14 +3,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 "$@" @@ -2,12 +2,12 @@ # New and better ls # TODO: fix simlinks, flags break them for some reason -ls_new () { - LC_ALL=C $( which ls ) -lAFh --color=always "$1" | awk '{ +ls_new() { + 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 - }' | column -t -l 3 -s ' '| tail -n +2 + }' | column -t -l 3 -s ' ' | tail -n +2 } dir="$1" @@ -9,11 +9,11 @@ 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}" ;; - "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} ;; - "current window (copy)") maim -q -d 0.2 -i "$(xdotool getactivewindow)" | ${xclip_cmd} ;; - "full screen (copy)") maim -q -d 0.2 | ${xclip_cmd} ;; - "copy selected image to text") tmpfile=$(mktemp /tmp/ocr-XXXXXX.png) && maim -u -s > "$tmpfile" && tesseract "$tmpfile" - -l eng | ${ocr_cmd} && rm "$tmpfile" ;; +"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} ;; +"current window (copy)") maim -q -d 0.2 -i "$(xdotool getactivewindow)" | ${xclip_cmd} ;; +"full screen (copy)") maim -q -d 0.2 | ${xclip_cmd} ;; +"copy selected image to text") tmpfile=$(mktemp /tmp/ocr-XXXXXX.png) && maim -u -s >"$tmpfile" && tesseract "$tmpfile" - -l eng | ${ocr_cmd} && rm "$tmpfile" ;; esac @@ -2,16 +2,22 @@ dir="$HOME/.obsidian" -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 +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 } -[ "$#" -ne 1 ] && { echo "Usage: newnote <note-name>" >&2; exit 1; } +[ "$#" -ne 1 ] && { + echo "Usage: newnote <note-name>" >&2 + exit 1 +} newnote "$1" exit 0 @@ -1,17 +1,23 @@ #!/bin/sh -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 +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 } -[ "$#" -ne 1 ] && { echo "Usage: newscript <script-name>" >&2; exit 1; } +[ "$#" -ne 1 ] && { + echo "Usage: newscript <script-name>" >&2 + exit 1 +} newscript "$1" exit 0 @@ -3,8 +3,8 @@ # This script is slow, but it works IFS=: for dir in $PATH; do - [ -d "$dir" ] || continue - for file in "$dir"/* "$dir"/.*; do - [ -f "$file" ] && [ -x "$file" ] && basename "$file" - done + [ -d "$dir" ] || continue + for file in "$dir"/* "$dir"/.*; do + [ -f "$file" ] && [ -x "$file" ] && basename "$file" + done done | sort -u @@ -7,7 +7,8 @@ xset r rate 200 50 setxkbmap us -option caps:swapescape # When caps lock is pressed only once, treat it as escape -killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape' +killall xcape 2>/dev/null +xcape -e 'Super_L=Escape' # Turn off caps lock if on since there is no longer a key for it xset -q | grep -q "Caps Lock:\s*on" && xdotool key Caps_Lock diff --git a/rm_whitespaces b/rm_whitespaces index 214f67c..de800c1 100755 --- a/rm_whitespaces +++ b/rm_whitespaces @@ -1,21 +1,24 @@ #!/bin/sh if [ "$#" -gt 1 ]; then - echo "Usage: delete_whitespaces <directory>" - exit 1 + echo "Usage: delete_whitespaces <directory>" + 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..."; exit 1; } +cd "$dir" || { + echo "Couldn't cd to directory. Exiting..." + exit 1 +} for file in "$dir"/*; do - newname="$( echo "$file" | sed 's/[ \t]/\_/g' )" - mv "$file" "$newname" + newname="$(echo "$file" | sed 's/[ \t]/\_/g')" + mv "$file" "$newname" done exit 0 @@ -1,6 +1,6 @@ #!/bin/sh -if echo "$1" | grep -q "https*://\S\+\.[A-Za-z]\+\S*" ; then +if echo "$1" | grep -q "https*://\S\+\.[A-Za-z]\+\S*"; then url="$1" else url="$(grep -Eom1 '<[^>]+(rel="self"|application/[a-z]+\+xml)[^>]+>' "$1" | @@ -14,5 +14,5 @@ RSSFILE="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls" if awk '{print $1}' "$RSSFILE" | grep "^$url$" >/dev/null; then notify-send "You already have this RSS feed." else - echo "$url" >> "$RSSFILE" && notify-send "RSS feed added." + echo "$url" >>"$RSSFILE" && notify-send "RSS feed added." fi @@ -5,35 +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 +while getopts "dfiPRrvW" opt; do + case $opt in + f) exec $realrm "$@" ;; + *) flags="$flags -$opt" ;; + esac done -shift $(( OPTIND - 1 )) +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 +for arg; do + newname="$archive/$(date "+%S.%M.%H.%d.%m").$(basename "$arg")" + if [ -f "$arg" ] || [ -d "$arg" ]; then + $copy "$arg" "$newname" + fi done exec $realrm "$flags" "$@" @@ -5,7 +5,7 @@ file=$(find . -mindepth 2 -type f 2>/dev/null | sed 's|^\./||' | sort | dmenu -i # 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 |