summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfilip <“filip.rabiega@gmail.com”>2025-10-10 19:10:02 +0200
committerfilip <“filip.rabiega@gmail.com”>2025-10-10 19:10:02 +0200
commit807de46d3a3cbef9a3c3c104f6db87b142e6eed5 (patch)
tree61a1a9bc26daad623ce6c04bb66ae39133ef0261
parent08204fc9b9f63015a1dc083b471c6839818eeb59 (diff)
downloadchadscripts-807de46d3a3cbef9a3c3c104f6db87b142e6eed5.tar.gz
chadscripts-807de46d3a3cbef9a3c3c104f6db87b142e6eed5.tar.bz2
chadscripts-807de46d3a3cbef9a3c3c104f6db87b142e6eed5.zip
used shfmt
-rwxr-xr-xbuku-dmenu8
-rwxr-xr-xchadsearch3
-rwxr-xr-xdecperc46
-rwxr-xr-xdictloop19
-rwxr-xr-xes2
-rwxr-xr-xextract_pdfs37
-rwxr-xr-xinpath59
-rwxr-xr-xlaunch8
-rwxr-xr-xlogrm8
-rwxr-xr-xlsn6
-rwxr-xr-xmaimpick14
-rwxr-xr-xnewnote22
-rwxr-xr-xnewscript26
-rwxr-xr-xprintpath8
-rwxr-xr-xremaps3
-rwxr-xr-xrm_whitespaces17
-rwxr-xr-xrssadd4
-rwxr-xr-xsaferm38
-rwxr-xr-xscan6
19 files changed, 172 insertions, 162 deletions
diff --git a/buku-dmenu b/buku-dmenu
index d77a0be..927e157 100755
--- a/buku-dmenu
+++ b/buku-dmenu
@@ -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"
diff --git a/decperc b/decperc
index a19ed95..7b1903f 100755
--- a/decperc
+++ b/decperc
@@ -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"
diff --git a/dictloop b/dictloop
index 6e9735b..a47e98c 100755
--- a/dictloop
+++ b/dictloop
@@ -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
diff --git a/es b/es
index b076862..dcea28b 100755
--- a/es
+++ b/es
@@ -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"
diff --git a/inpath b/inpath
index bab47b4..b8bf568 100755
--- a/inpath
+++ b/inpath
@@ -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
diff --git a/launch b/launch
index 16add49..f7189ed 100755
--- a/launch
+++ b/launch
@@ -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 &
diff --git a/logrm b/logrm
index bd9f29c..f139f82 100755
--- a/logrm
+++ b/logrm
@@ -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 "$@"
diff --git a/lsn b/lsn
index 46abd71..b3f07ea 100755
--- a/lsn
+++ b/lsn
@@ -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"
diff --git a/maimpick b/maimpick
index 1f0c4a3..0ef8455 100755
--- a/maimpick
+++ b/maimpick
@@ -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
diff --git a/newnote b/newnote
index c1b1835..ddf5c1b 100755
--- a/newnote
+++ b/newnote
@@ -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
diff --git a/newscript b/newscript
index 0b47bbd..f6d11b0 100755
--- a/newscript
+++ b/newscript
@@ -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
diff --git a/printpath b/printpath
index 55a3212..3c59e8f 100755
--- a/printpath
+++ b/printpath
@@ -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
diff --git a/remaps b/remaps
index df6051f..c18a9b9 100755
--- a/remaps
+++ b/remaps
@@ -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
diff --git a/rssadd b/rssadd
index 910fca3..6fa8718 100755
--- a/rssadd
+++ b/rssadd
@@ -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
diff --git a/saferm b/saferm
index 426f4a0..ca49554 100755
--- a/saferm
+++ b/saferm
@@ -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" "$@"
diff --git a/scan b/scan
index f06d5a4..c35798f 100755
--- a/scan
+++ b/scan
@@ -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