diff options
Diffstat (limited to '.local')
39 files changed, 617 insertions, 230 deletions
diff --git a/.local/bin/background-cleanup b/.local/bin/background-cleanup new file mode 100755 index 0000000..c61caec --- /dev/null +++ b/.local/bin/background-cleanup @@ -0,0 +1,27 @@ +#!/bin/sh + +[ -z "$CD_HISTFILE" ] && + export CD_HISTFILE="${XDG_STATE_HOME:-$HOME/.local/state}/cd_history" + +[ -z "$OPEN_HISTFILE" ] && + export OPEN_HISTFILE="${XDG_STATE_HOME:-$HOME/.local/state}/open_history" + +on_ac_power() { [ "$(cat /sys/class/power_supply/ACAD/online)" = 1 ]; } + +sleep 10 +on_ac_power || echo "System not plugged to AC Adapter, waiting..." + +until on_ac_power; do + sleep 10m +done + +echo "[cleanup] Cleaning $CD_HISTFILE" +cleanup-history-file "$CD_HISTFILE" + +echo "[cleanup] Cleaning $OPEN_HISTFILE" +cleanup-history-file "$OPEN_HISTFILE" + +echo "[cleanup] Cleaning orphaned packages..." +pacman -Qtdq | xargs -r sudo pacman -Rns --noconfirm + +echo "[cleanup] Finished Cleaning." diff --git a/.local/bin/desktop/brightness b/.local/bin/desktop/brightness index 11733f4..74d3e36 100755 --- a/.local/bin/desktop/brightness +++ b/.local/bin/desktop/brightness @@ -15,6 +15,7 @@ case "$1" in esac brightness="$(brightnessctl --machine-readable | cut -d, -f4)" +echo "$brightness" > "${XDG_STATE_HOME:-$HOME/.local/state}/brightness" if [ -n "$TMUX" ]; then tmux display "Brightness: $brightness" diff --git a/.local/bin/desktop/dmenu-file-history b/.local/bin/desktop/dmenu-file-history new file mode 100755 index 0000000..0997c76 --- /dev/null +++ b/.local/bin/desktop/dmenu-file-history @@ -0,0 +1,6 @@ +#!/bin/sh + +[ -n "$OPEN_HISTFILE" ] || + export OPEN_HISTFILE="${XDG_STATE_HOME:-$HOME/.local/state}/open_history" + +tac "$OPEN_HISTFILE" | dmenu -i -l 30 | xargs -I{} "${OPENER:-xdg-open}" "{}" diff --git a/.local/bin/desktop/dmenu-sound b/.local/bin/desktop/dmenu-sound new file mode 100755 index 0000000..967e9fa --- /dev/null +++ b/.local/bin/desktop/dmenu-sound @@ -0,0 +1,6 @@ +#!/bin/sh + +node="$(wpctl status | grep vol: | cut -c5- | dmenu -i -l 30 | + sed -E "s/^[ *]*([0-9]{2}).*$/\1/")" + +[ -n "$node" ] && wpctl set-default "$node" diff --git a/.local/bin/desktop/dmenu-unicode b/.local/bin/desktop/dmenu-unicode index 16e1cfc..5a3a0f5 100755 --- a/.local/bin/desktop/dmenu-unicode +++ b/.local/bin/desktop/dmenu-unicode @@ -1,6 +1,6 @@ #!/bin/sh -chosen=$(cat ~/.local/share/chars/* | dmenu -i -l 25 -fn :size=20) +chosen=$(cat ~/.local/share/chars/* | dmenu -i -l 25) [ -z "$chosen" ] && exit diff --git a/.local/bin/desktop/setbg b/.local/bin/desktop/setbg index c288895..8277caf 100755 --- a/.local/bin/desktop/setbg +++ b/.local/bin/desktop/setbg @@ -36,6 +36,6 @@ else [ -f "$zathuraconf.bak" ] && unlink "$zathuraconf" && mv "$zathuraconf.bak" "$zathuraconf" fi -xwallpaper --zoom "$bgloc" +xwallpaper --focus "$bgloc" # If running, dwm hit the key to refresh the color scheme. pidof dwm >/dev/null && xdotool key super+F5 diff --git a/.local/bin/desktop/setdp b/.local/bin/desktop/setdp index 48c6a7a..afe4498 100755 --- a/.local/bin/desktop/setdp +++ b/.local/bin/desktop/setdp @@ -13,8 +13,8 @@ if [ "$display_count" = 2 ]; then for display in $displays; do case "$display" in - eDP*) export PRIMARY="$display"; set -- "$@" --output "$display" --mode 1920x1080 --primary --pos 0x270 ;; - HDMI*) set -- "$@" --output "$display" --mode 1920x1080 --pos 1920x0 --scale "1.25x1.25" ;; + eDP*) export PRIMARY="$display"; set -- "$@" --output "$display" --mode 1920x1080 --primary --pos 0x162 ;; + HDMI*) set -- "$@" --output "$display" --mode 1920x1080 --pos 2112x0 --scale "1.25x1.25" ;; esac done diff --git a/.local/bin/desktop/windowshot b/.local/bin/desktop/windowshot new file mode 100755 index 0000000..e4de6b0 --- /dev/null +++ b/.local/bin/desktop/windowshot @@ -0,0 +1,3 @@ +#!/bin/sh + +import -silent -window "$(xdotool selectwindow)" png:- | xclip -sel clipboard -t image/png -i diff --git a/.local/bin/desktop/zbarscreen b/.local/bin/desktop/zbarscreen new file mode 100755 index 0000000..e325ce5 --- /dev/null +++ b/.local/bin/desktop/zbarscreen @@ -0,0 +1,3 @@ +#!/bin/sh + + import -silent -window root bmp:- | zbarimg - | sed -e 's/QR-Code://' | xclip -selection clipboard diff --git a/.local/bin/desktop/zbarwindow b/.local/bin/desktop/zbarwindow new file mode 100755 index 0000000..7085f69 --- /dev/null +++ b/.local/bin/desktop/zbarwindow @@ -0,0 +1,3 @@ +#!/bin/sh + +import -silent -window "$(xdotool selectwindow)" bmp:- | zbarimg - | sed -e 's/QR-Code://' | xclip -selection clipboard diff --git a/.local/bin/development/envrun b/.local/bin/development/envrun new file mode 100755 index 0000000..aad0822 --- /dev/null +++ b/.local/bin/development/envrun @@ -0,0 +1,55 @@ +#!/bin/sh + +help() { echo "envrun - run programs in an isolated home directory + +USAGE: + envrun [OPTION]... COMMAND + +OPTIONS: + -d ENVHOME use the ENVHOME environment directory + -h show this help message"; } + +while getopts 'd:h' o; do case "$o" in + d) export ENVHOME="$OPTARG" ;; + *) help >&2; exit ;; +esac done +shift $((OPTIND - 1)) + +export HOME="${ENVHOME:-"$PWD"}" +export XDG_CACHE_HOME="$HOME/.cache" +export XDG_CONFIG_HOME="$HOME/.config" +export XDG_DATA_HOME="$HOME/.local/share" +export XDG_STATE_HOME="$HOME/.local/state" + +ensure_dirs() { + for dir in "$@"; do + [ -d "$dir" ] || { missing=1; break; } + done + + [ "$missing" = 1 ] || return + printf "\nFollowing directories will be created.\n\n" + for dir in "$@"; do + [ -d "$dir" ] || echo "$dir/" + done + + printf "\ncontinue? [y/N] " + read -r ans + case "$ans" in + y|Y) echo; mkdir -pv "$@"; echo ;; + *) exit ;; + esac +} + +ensure_dirs \ + "$XDG_CACHE_HOME" \ + "$XDG_CONFIG_HOME" \ + "$XDG_DATA_HOME" \ + "$XDG_STATE_HOME" + +[ "$#" -lt 1 ] && { + echo "Please provide a command to run." + exit +} + +"$@" + diff --git a/.local/bin/shorts/font2svg b/.local/bin/development/font2svg index 539972d..539972d 100755 --- a/.local/bin/shorts/font2svg +++ b/.local/bin/development/font2svg diff --git a/.local/bin/development/gh-clone-all b/.local/bin/development/gh-clone-all index d2b3cdc..fed6efe 100755 --- a/.local/bin/development/gh-clone-all +++ b/.local/bin/development/gh-clone-all @@ -12,5 +12,5 @@ while [ "$page" -lt "$max" ]; do page=$(( page + 1 )) curl "https://api.github.com/$cntx/$name/repos?page=$page&per_page=100" | sed -E '/^\s*"clone_url": "(.*)",$/!d; s//\1/' | - xargs -L1 echo git clone + xargs -L1 git clone done diff --git a/.local/bin/development/github-repo-size b/.local/bin/development/gh-repo-size index 0cedd88..0cedd88 100755 --- a/.local/bin/development/github-repo-size +++ b/.local/bin/development/gh-repo-size diff --git a/.local/bin/development/ghclone b/.local/bin/development/ghclone new file mode 100755 index 0000000..2e11024 --- /dev/null +++ b/.local/bin/development/ghclone @@ -0,0 +1,5 @@ +#!/bin/sh + +URL="https://github.com/$1/${2:-$1}" +echo "Clone URL: $URL" +git clone "$URL" diff --git a/.local/bin/development/gi b/.local/bin/development/gi new file mode 100755 index 0000000..f7884a9 --- /dev/null +++ b/.local/bin/development/gi @@ -0,0 +1,8 @@ +#!/bin/sh + +# gi (git-ignore) - open current repo's gitingore file in $EDITOR + +[ -f .gitignore ] && { ${EDITOR:-nvim -p} .gitignore; exit; } + +TOPLEVEL="$(git rev-parse --show-toplevel)" || exit +find "$TOPLEVEL" -name ".gitignore" | xargs -r ${EDITOR:-nvim -p} diff --git a/.local/bin/development/gitpush b/.local/bin/development/gitpush index 7774a7b..2c503ca 100755 --- a/.local/bin/development/gitpush +++ b/.local/bin/development/gitpush @@ -1,12 +1,6 @@ #!/bin/sh push_to_remote() { - case "$(git config --get remote.origin.url)" in - *csstudent41*) sshadd ~/.ssh/github.com_id_ed25519 ;; - *labstudent41*) sshadd ~/.ssh/labstudent41_id_ed25519 ;; - *vtc-tech*) sshadd ~/.ssh/vartaktechclub_id_ed25519 ;; - esac - git add --all git commit && git push -u origin } diff --git a/.local/bin/development/gitw b/.local/bin/development/gitweb index 881c81c..881c81c 100755 --- a/.local/bin/development/gitw +++ b/.local/bin/development/gitweb diff --git a/.local/bin/development/nx b/.local/bin/development/nx index 862be99..8305487 100755 --- a/.local/bin/development/nx +++ b/.local/bin/development/nx @@ -21,7 +21,7 @@ shift $((OPTIND - 1)) [ "$#" -gt 1 ] && err "too many arguments. Only one expected" -new_script() { +new_file() { cat << EOF > "$1" #!/bin/sh @@ -47,77 +47,8 @@ EOF chmod u+x -- "$1" || exit } - -new_c_file() { - cat << EOF > "$1" -#include <stdio.h> - -int main() -{ - printf("Hello\n"); - - return 0; -} -EOF -} - - -new_cpp_file() { - cat << EOF > "$1" -#include <iostream> - -using namespace std; - -int main() -{ - cout << "Hello" << endl; - - cin.get(); - return 0; -} -EOF -} - - -new_py_file() { - cat << EOF > "$1" -import timeit - -print("Finished in %fs" % timeit.timeit()) -EOF -} - - -new_java_file() { - PATTERN="Scanner" - VIMCMDS="normal!2n\n noh" - cat << EOF > "$1" -import java.util.Scanner; - -class ${1%.java} { - public static void main(String args[]) { - Scanner sc = new Scanner(System.in); - - System.out.println("Finished!"); - sc.close - } -} -EOF -} - - file="$1" -new_file() { - case "$file" in - *.c) new_c_file "$file" ;; - *.cpp) new_cpp_file "$file" ;; - *.py) new_py_file "$file" ;; - *.java) new_java_file "$file" ;; - *) new_script "$file" ;; - esac -} - if [ -f "$file" ]; then [ ! -w "$file" ] && chmod u+rw "$file" if [ -s "$file" ]; then @@ -134,15 +65,5 @@ fi ls -lF --color -- "$file" -case "$EDITOR" in - '') echo "$0: \$EDITOR variable not set" >&2 && exit 1 ;; - vi|*vim*) - VIMCONF="$(mktemp)"; export VIMCONF - [ -n "$VIOPTS" ] && echo "set $VIOPTS" >> "$VIMCONF" - [ -n "$PATTERN" ] && echo "/$PATTERN" >> "$VIMCONF" - [ -n "$VIMCMDS" ] && echo "$VIMCMDS" >> "$VIMCONF" - $EDITOR -S "$VIMCONF" "$file" - rm -f "$VIMCONF" - ;; - *) $EDITOR "$file" ;; -esac; exit +${EDITOR} "$file" + diff --git a/.local/bin/fcode b/.local/bin/fcode index 073bec4..2c8041d 100755 --- a/.local/bin/fcode +++ b/.local/bin/fcode @@ -4,9 +4,8 @@ # place your charecter files in plain text in ~/.local/share/chars/* if [ "$OPENFLAG" = 0 ]; then - notify-send fzf-unicode "$*" chosen="$(printf '%s\n' "$@" | cut -d\ -f1 | tr -d '\n')" - echo "$chosen" | xclip -selection clipboard + printf "%s" "$chosen" | xclip -selection clipboard notify-send "'$chosen' copied to clipboard." exit fi @@ -16,10 +15,10 @@ fi mkdir -pv "$FZF_HISTDIR" export FZF_HIST="$FZF_HISTDIR/unicode_history" -cut -d ';' -f1 ~/.local/share/chars/* | +cat ~/.local/share/chars/* | fzf -m --history="$FZF_HIST" \ --header="Copy Emojis to Clipboard" --header-first \ --preview 'printf "%s\n" {+} | cut -d\ -f1 | tr -d "\n"' \ --preview-window=nohidden,up,1 \ --bind 'ctrl-/:change-preview-window(down|up)' \ - --bind 'enter:execute(echo {q} >> $FZF_HIST; OPENFLAG=0 fzf-unicode {+})' + --bind "enter:execute(echo {q} >> \"$FZF_HIST\"; OPENFLAG=0 \"$0\" {+})" diff --git a/.local/bin/fgr b/.local/bin/fgr new file mode 100755 index 0000000..34d69cc --- /dev/null +++ b/.local/bin/fgr @@ -0,0 +1,82 @@ +#!/bin/sh + +# https://junegunn.github.io/fzf/tips/ripgrep-integration/#6-bind-enter-to-become-action + +help() { echo "fgr - grep with fzf (fzf-grep) + +USAGE: + fgr [OPTION]... PATTERN + +OPTIONS: + -r real time grepping with fzf prompt + -h show this help message + +ENVIRONMENT VARIABLES: + FZF_GREP_COMMAND overrides the default grep command whose content is piped into fzf + FZF_GREP_OPENER overrides the default opener used to open selection on pressing 'enter' + "; } + +err() { printf '%s: %s\n' "$0" "$@" >&2; exit 1; } + +while getopts 'rh' o; do case "$o" in + r) rflag=1 ;; + h) help >&2; exit ;; + ?) err "invalid option passed" ;; +esac done +shift $((OPTIND - 1)) + +[ -z "$FZF_HISTDIR" ] && + export FZF_HISTDIR="${XDG_STATE_HOME:-$HOME/.local/state}/fzf" + +mkdir -pv "$FZF_HISTDIR" +export FZF_HIST="$FZF_HISTDIR/grep_history" + +[ -z "$FZF_GREP_COMMAND" ] && + if command -v rg >/dev/null; then + FZF_GREP_COMMAND="rg --smart-case --column --color=always" + elif command -v git >/dev/null; then + FZF_GREP_COMMAND="git grep -I --ignore-case --column --color=always" + else + FZF_GREP_COMMAND="grep -Rnsi --exclude-dir=.git --color=always" + fi + +[ -z "$FZF_GREP_RELOAD" ] && + FZF_GREP_RELOAD="reload($FZF_GREP_COMMAND {q} || :)" + +[ -z "$FZF_GREP_OPENER" ] && FZF_GREP_OPENER=' + if [[ $FZF_SELECT_COUNT -eq 0 ]]; then + $EDITOR {1} +{2} # No selection. Open the current line in Vim. + else + $EDITOR +cw -q {+f} # Build quickfix list for the selected items. + fi + ' + +FZF_OPENER=" + # update history + sed -i '\\|^{q}$|d' \"$FZF_HIST\" + echo {q} >> \"$FZF_HIST\" + + $FZF_GREP_OPENER + " + +query="$*" + +fzf() { $FZF_GREP_COMMAND "$query" | command fzf "$@" \ + --ansi --multi --exit-0 --header-first \ + --history="$FZF_HIST" \ + --bind "enter:execute($FZF_OPENER)" \ + --bind "ctrl-o:become($FZF_OPENER)" \ + --bind 'ctrl-v:toggle-preview,ctrl-space:toggle-preview' \ + --bind "ctrl-r:reload($FZF_GREP_COMMAND '$query')" \ + --bind 'alt-a:select-all,alt-d:deselect-all,ctrl-/:toggle-preview' \ + --delimiter : \ + --preview 'bat --style=full --color=always --highlight-line {2} {1}' \ + --preview-window '~4,+{2}+4/3,<80(up)'; } + +if [ "$rflag" = 1 ]; then + fzf --disabled --query "$query" \ + --header "COMMAND: $FZF_GREP_COMMAND <prompt-query>" \ + --bind "change:$FZF_GREP_RELOAD" +else + fzf --header "COMMAND: $FZF_GREP_COMMAND '$query'" +fi diff --git a/.local/bin/fgrp b/.local/bin/fgrp deleted file mode 100755 index 18bcabd..0000000 --- a/.local/bin/fgrp +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -# fzf-grep: browse through grepped lines using fzf - -if [ "$OPENFLAG" = 0 ]; then - location="$(echo "$*" | sed 's/^\(.*\):\([0-9]\+\):.*$/\1|\2/')" - file="${location%|*}"; line="${location##*|}" - case "${OPENWITH:=$EDITOR}" in - ''|vi|*vim*) $OPENWITH +"$line" "$file" ;; - *) $OPENWITH "$file" ;; - esac; exit -fi - -[ -z "$FZF_HISTDIR" ] && - export FZF_HISTDIR="${XDG_STATE_HOME:-$HOME/.local/state}/fzf" -mkdir -pv "$FZF_HISTDIR" -export FZF_HIST="$FZF_HISTDIR/grep_history" - -cmd="grep -Rnsi --exclude-dir=.git --exclude-dir=node_modules --color=always" -$cmd "$@" | - fzf --ansi \ - --history="$FZF_HIST" \ - --prompt="grep > " \ - --preview='preview "$(echo {1} | cut -d: -f1)"' \ - --preview-window="hidden" \ - --bind 'ctrl-v:toggle-preview,ctrl-space:toggle-preview' \ - --bind "ctrl-r:reload($cmd $*)" \ - --bind 'enter:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 fgrp {})' \ - --bind 'alt-e:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 OPENWITH=${EDITOR:-vi} fgrp {})' \ - --bind 'alt-o:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 OPENWITH=${OPENER:-xdg-open} fgrp {})' \ - --bind 'alt-O:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 OPENWITH=${FILES:-lf} fgrp {})' diff --git a/.local/bin/open b/.local/bin/open index 5936451..dc90c9b 100755 --- a/.local/bin/open +++ b/.local/bin/open @@ -1,5 +1,7 @@ #!/bin/sh +[ -t 1 ] || exec "$TERMINAL" -e open "$@" + [ -z "$1" ] && echo "USAGE: open <FILE>" >&2 && exit 1 for file in "$@"; do @@ -7,16 +9,16 @@ for file in "$@"; do *.pdf|*.djvu|*.epub) setsid -f zathura "$file" 2>/dev/null ;; *.png|*.jpg|*.jpeg|*.webp) setsid -f nsxiv "$file" ;; - *.gif|*.mkv|*.mp3|*.mp4|*.webm|*.ogg) ${PLAYER:-mpv --sub-auto=fuzzy} "$file" ;; - *.html) ${BROWSER:-w3m} "$file" ;; + *.gif|*.mkv|*.mp3|*.mp4|*.webm|*.ogg) ${PLAYER:-mpv --no-config --sub-auto=fuzzy} "$file" ;; + *.html) ${BROWSER:-w3m --enable-mouse} "$file" ;; *.pl.txt) fpl "$file" ;; *.txt|*.description) ${PAGER:-less} "$file" ;; - *.md) glow --pager --width $(("$(tput cols)" - 5)) "$file" ;; + *.md) glow --pager --width $(($(tput cols) - 5)) "$file" ;; *.css|*.json|*.ipynb|*.vim|*.lua|*.iso|*.zip) LESSOPEN="|preview %s" less -r "$file" ;; *.srt) fzf-subtitles -o "$file" ;; *.dig) setsid -f digital "$file" ;; *.doc|*.docx|*.ppt|*.pptx) setsid -f libreoffice "$file" ;; - *.sc|*.xls|*.xlsx) sc-im "$file" ;; + *.sc|*.xls|*.xlsx) /usr/bin/sc-im "$file" ;; *.sim1) simulide "$file" ;; *.xz) ${EDITOR:-nvim} "$file" ;; @@ -24,14 +26,14 @@ for file in "$@"; do filetype="$(file --dereference --brief --mime-type "$file")" case "$filetype" in inode/directory) ${FILES:-lf} "$file" ; exit ;; - text/html*) ${BROWSER:-w3m} "$file" ;; + text/html*) ${BROWSER:-w3m --enable-mouse} "$file" ;; *pdf|*djvu|*epub+zip|*oxps|*fictionbook) setsid -f zathura "$file" 2>/dev/null ;; text/*|*json|*zip|*zstd|*javascript) "${EDITOR:-nvim}" "$file" ;; application/vnd.openxmlformats-officedocument.*) setsid -f libreoffice "$file" ;; application/sc) sc-im "$file" ;; application/x-executable) "$file" ;; image/*) setsid -f nsxiv "$file" ;; - video/*|audio/*) ${PLAYER:- mpv --sub-auto=fuzzy} "$file" ;; + video/*|audio/*) ${PLAYER:- mpv --no-config --sub-auto=fuzzy} "$file" ;; *) xdg-open "$file" || exit [ -n "$DISPLAY" ] && notify-send "⚠️ open: unknown filetype" "$filetype" @@ -42,8 +44,9 @@ for file in "$@"; do esac - [ -z "$OPEN_HISTFILE" ] && + [ -n "$OPEN_HISTFILE" ] || export OPEN_HISTFILE="${XDG_STATE_HOME:-$HOME/.local/state}/open_history" + file="$(realpath "$file")" sed -i "\|^$file$|d" "$OPEN_HISTFILE" echo "$file" >> "$OPEN_HISTFILE" diff --git a/.local/bin/preview b/.local/bin/preview index 235f0e0..5201fcd 100755 --- a/.local/bin/preview +++ b/.local/bin/preview @@ -6,8 +6,7 @@ if [ -d "$1" ]; then else ls -lhAF --group-directories-first --color=always -- "$1" fi - readme="$(find "$1" -maxdepth 1 -name "README.*" | head -1)" - [ -z "$readme" ] || preview "$readme" + find "$1" -maxdepth 1 -iname "README*" | xargs -r preview exit fi @@ -18,8 +17,8 @@ case "$1" in '') echo "USAGE: preview <FILE>" >&2; exit 1 ;; *.html) w3m -dump "$1" ;; *.md) glow "$1" ;; - # *.vim) highlight --syntax=vim --replace-tabs=2 -- "$1" ;; - *.js|*.vim|*.lua) highlight -- "$1" ;; + *.vim) highlight --syntax=vim --replace-tabs=2 -- "$1" ;; + *.js*|*.ts*|*.lua) highlight --replace-tabs=2 -- "$1" ;; *.txt|*.description|*.srt) cat -- "$1" ;; *.png|*.jpg|*.jpeg|*.webp|*.mp3|*.ogg|*.mp4|*.mkv|*.webm) mediainfo -- "$1" ;; *.info.json) jq -C . "$1" ;; @@ -39,7 +38,6 @@ case "$1" in *odt|*.ods|*.odp|*.sxw) odt2txt "$1" ;; *.doc) catdoc "$1" ;; *.docx) docx2txt "$1" - ;; - # *.csv) sed s/,/\\n/g "$1" ;; *) filetype=$(file --dereference --brief --mime-type "$1") @@ -47,7 +45,7 @@ case "$1" in *html) w3m -dump "$1" ;; text/markdown) glow "$1" ;; application/json) highlight --syntax=json --replace-tabs=2 -- "$1" ;; - text/*|*javascript) highlight --force -- "$1" ;; + text/*|*javascript) highlight --force --replace-tabs=2 -- "$1" ;; audio/*|video/*|image/*) mediainfo -- "$1" ;; *xz) xz --list "$1" ;; *zip|*tar*|*7z*|*bzip2) atool --list -- "$1" ;; diff --git a/.local/bin/shortcuts b/.local/bin/shortcuts index 545799f..368f1ba 100755 --- a/.local/bin/shortcuts +++ b/.local/bin/shortcuts @@ -1,24 +1,26 @@ #!/bin/sh -config="${XDG_CONFIG_HOME:-$HOME/.config}" -bmdirs="$config/shell/bm-dirs" -bmfiles="$config/shell/bm-files" +bmdirs="${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" +bmfiles="${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-files" -shell_shortcuts="$config/shell/shortcutrc" -zsh_named_dirs="$config/zsh/zshnameddirrc" -lf_shortcuts="$config/lf/shortcutrc" -vim_shortcuts="$config/nvim/shortcuts.vim" +shell_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc" +shell_env_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutenvrc" +zsh_named_dirs="${XDG_CONFIG_HOME:-$HOME/.config}/zsh/zshnameddirrc" +lf_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/lf/shortcutrc" +vim_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/nvim/shortcuts.vim" rm -f "$zsh_named_dirs" "$lf_shortcuts" "$vim_shortcuts" -printf "# vim: filetype=sh\n" > "$shell_shortcuts" +printf "# vim: filetype=sh\\nalias \\\\\n" > "$shell_shortcuts" +printf "# vim: filetype=sh\\nexport \\\\\n" > "$shell_env_shortcuts" eval "echo \"$(cat "$bmdirs")\"" | awk -F'\t' " !/^\s*#/ && !/^\s*$/ { gsub(\"\\\s*#.*$\", \"\"); - printf(\"alias %s='cd %s && ls -A'\n\", \$1, \$2) >> \"$shell_shortcuts\" + printf(\"%s='cd %s && ls -A' \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" + printf(\"%s=\42%s\42 \\\\\n\", \$1, \$2) >> \"$shell_env_shortcuts\" printf(\"hash -d %s=%s\n\", \$1, \$2) >> \"$zsh_named_dirs\" - printf(\"map c%s :cd %s\n\", \$1, \$2) >> \"$lf_shortcuts\" + printf(\"map C%s :cd %s\n\", \$1, \$2) >> \"$lf_shortcuts\" printf(\"cmap ;%s %s\n\", \$1, \$2) >> \"$vim_shortcuts\" } " @@ -27,7 +29,8 @@ eval "echo \"$(cat "$bmfiles")\"" | awk -F'\t' " !/^\s*#/ && !/^\s*$/ { gsub(\"\\\s*#.*$\", \"\"); - printf(\"alias %s='\$EDITOR %s'\n\", \$1, \$2) >> \"$shell_shortcuts\" + printf(\"%s='\$EDITOR %s' \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" + printf(\"%s=\42%s\42 \\\\\n\", \$1, \$2) >> \"$shell_env_shortcuts\" printf(\"hash -d %s=%s\n\", \$1, \$2) >> \"$zsh_named_dirs\" printf(\"map E%s $\$EDITOR %s\n\", \$1, \$2) >> \"$lf_shortcuts\" printf(\"cmap ;%s %s\n\", \$1, \$2) >> \"$vim_shortcuts\" diff --git a/.local/bin/shorts/adbs b/.local/bin/shorts/adbs index bca7733..20bba2b 100755 --- a/.local/bin/shorts/adbs +++ b/.local/bin/shorts/adbs @@ -1,3 +1,7 @@ #!/bin/sh -adb -s "${ADB_DEVICE}" shell "$@" +if [ -n "$ADB_DEVICE" ]; then + adb -s "${ADB_DEVICE}" shell "$@" +else + adb shell "$@" +fi diff --git a/.local/bin/shorts/mailsyncd b/.local/bin/shorts/mailsyncd new file mode 100755 index 0000000..fdc132f --- /dev/null +++ b/.local/bin/shorts/mailsyncd @@ -0,0 +1,6 @@ +#!/bin/sh + +while true; do + mailsync + sleep 10m +done diff --git a/.local/bin/shorts/mk b/.local/bin/shorts/mk new file mode 100755 index 0000000..392320f --- /dev/null +++ b/.local/bin/shorts/mk @@ -0,0 +1,5 @@ +#!/bin/sh + +# make a file in specified path + +mkdir -pv "$(dirname "$1")" && touch "$1" diff --git a/.local/bin/shorts/nvc b/.local/bin/shorts/nvc new file mode 100755 index 0000000..0df642d --- /dev/null +++ b/.local/bin/shorts/nvc @@ -0,0 +1,4 @@ +#!/bin/sh + +# assumes NvChad is configured in ~/Dev/.config/nvim +envrun -d "$HOME/Dev" nvim "$@" diff --git a/.local/bin/shorts/rep b/.local/bin/shorts/rep new file mode 100755 index 0000000..78623b6 --- /dev/null +++ b/.local/bin/shorts/rep @@ -0,0 +1,3 @@ +#!/bin/sh + +fd | sad "$@" diff --git a/.local/bin/statusbar/disk-io b/.local/bin/statusbar/disk-io new file mode 100755 index 0000000..daf8e58 --- /dev/null +++ b/.local/bin/statusbar/disk-io @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2016 James Murphy +# Licensed under the terms of the GNU GPL v2 only. +# +# i3blocks blocklet script to monitor disk io + +label="${LABEL:-""}" +dt="${DT:-5}" +MB_only="${MB_ONLY:-0}" +kB_only="${KB_ONLY:-0}" +width="${WIDTH:-4}" +MB_precision="${MB_PRECISION:-1}" +kB_precision="${KB_PRECISION:-0}" +regex="${REGEX:-$BLOCK_INSTANCE}" +regex="${regex:-/^(s|h)d[a-zA-Z]+/}" +threshold="${THRESHOLD:-0}" +warn_color="${WARN_COLOR:-#FF0000}" +sep="${SEPARATOR:-/}" +unit_suffix="${SUFFIX:-B/s}" +align="${ALIGN--}" + +function list_devices { + echo "Devices iostat reports that match our regex:" + iostat | awk '$1~/^(s|h)d[a-zA-Z]+/{print $1}' +} + +while getopts L:t:w:p:P:R:s:ST:C:lLMmKkh opt; do + case "$opt" in + L) label="$OPTARG" ;; + t) dt="$OPTARG" ;; + w) width="$OPTARG" ;; + p) kB_precision="$OPTARG" ;; + P) MB_precision="$OPTARG" ;; + R) regex="$OPTARG" ;; + s) sep="$OPTARG" ;; + S) unit_suffix="" ;; + T) threshold="$OPTARG" ;; + C) warn_color="$OPTARG" ;; + l) list_devices; exit 0 ;; + M|m) MB_only=1 ;; + K|k) kB_only=1 ;; + h) printf \ +"Usage: disk-io [-t time] [-w width] [-p kB_precision] [-P MB_precision] [-R regex] [-s separator] [-S] [-T threshold [-C warn_color]] [-k|-M] [-l] [-h] +Options: +-L\tLabel to put in front of the text. Default: $label +-t\tTime interval in seconds between measurements. Default: $dt +-w\tThe width of printed floats. Default: $width +-p\tThe precision of kB/s floats. Default: $kB_precision +-P\tThe precision of MB/s floats. Default: $MB_precision +-R\tRegex that devices must match. Default: $regex +-s\tSeparator to put between rates. Default: $sep +-S\tShort units, omit B/s in kB/s and MB/s. +-T\tRate in kB/s to exceed to trigger a warning. Default: not enabled +-C\tColor to change the blocklet to warn the user. Default: $warn_color +-l\tList devices that iostat reports +-M\tDo not switch between MB/s and kB/s, use only MB/s +-k\tDo not switch between MB/s and kB/s, use only kB/s +-h\tShow this help text +" && exit 0;; + esac +done + +iostat -dyz "$dt" | awk -v sep="$sep" " + BEGIN { + rx = wx = 0; + } + { + if(\$0 == \"\") { + if ($threshold > 0 && (rx >= $threshold || wx >= $threshold)) { + printf \"<span color='$warn_color'>\"; + } + printf \"$label\"; + if(!$kB_only && ($MB_only || rx >= 1024 || wx >= 1024)) { + printf \"%$align$width.${MB_precision}f%s%$width.${MB_precision}f M$unit_suffix\", rx/1024, sep, wx/1024; + } + else { + printf \"%$align$width.${kB_precision}f%s%$width.${kB_precision}f k$unit_suffix\", rx, sep, wx; + } + if ($threshold > 0 && (rx >= $threshold || wx >= $threshold)) { + printf \"</span>\"; + } + printf \"\n\"; + fflush(stdout); + } + else if(\$1~/^Device:?/) { + rx = wx = 0; + } + else if(\$1~$regex) { + rx += \$3; + wx += \$4; + } + }" diff --git a/.local/bin/statusbar/disk_usage b/.local/bin/statusbar/disk_usage new file mode 100755 index 0000000..b129fc9 --- /dev/null +++ b/.local/bin/statusbar/disk_usage @@ -0,0 +1,123 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# MIT License + +# Copyright (c) 2017 Christian Schläppi + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import os +import sys +import subprocess + + +def get_disk_stats(mp): + stat = os.statvfs(mp) + + total = stat.f_blocks * stat.f_frsize / 1024 ** 3 + avail = stat.f_bavail * stat.f_frsize / 1024 ** 3 + used = total - avail + + return { + 'avail': avail, + 'total': total, + 'used': used, + 'perc_used': 100 * used / total + } + + +def launch_ncdu(mp): + cmd = [ + '/usr/bin/sakura', + '-t', + 'pop-up', + '-e', + '/usr/bin/ncdu %s' % mp, + '-x', + ] + + subprocess.Popen( + cmd, + stdout=open(os.devnull, 'w'), + stderr=subprocess.STDOUT + ) + + +def parse_args(): + args = { + 'warn_threshold': 80, + 'crit_threshold': 90, + 'warn_color': '#d6af4e', + 'crit_color': '#d64e4e', + 'format': '{used:.1f}G/{total:.1f}G ({perc_used:.1f}%) - {avail:.1f}G' + } + + try: + for arg in sys.argv[1:]: + key, value = arg.split('=') + args[key] = int(value) if value.isdigit() else value + except (KeyError, ValueError): + # ValuError in case user does something weird + pass + + return args + + +def get_instance(): + p = os.getenv('BLOCK_INSTANCE') + if p and os.path.exists(p): + return p + + return os.getenv('HOME') + + +def main(): + + output_color = '' + args = parse_args() + m_point = get_instance() + stats = get_disk_stats(m_point) + + # get some more info when not called by i3blocks + if not os.getenv('BLOCK_NAME'): + print('Args: %s' % args) + print('Stats: %s' % stats) + print('Mount Point: %s' % m_point) + + # print stats with format if given + print(args['format'].format(**stats)) + print() + + # determine color + if args['crit_threshold'] > int(stats['perc_used']) >= args['warn_threshold']: + output_color = args['warn_color'] + elif stats['perc_used'] >= args['crit_threshold']: + output_color = args['crit_color'] + + print(output_color) + + # handle click-event + _button = os.getenv('BLOCK_BUTTON') + if _button and int(_button) == 1: + launch_ncdu(m_point) + + +if __name__ == '__main__': + main() diff --git a/.local/bin/statusbar/i3battery b/.local/bin/statusbar/i3battery index 5b2fb15..17a4dfd 100755 --- a/.local/bin/statusbar/i3battery +++ b/.local/bin/statusbar/i3battery @@ -47,7 +47,7 @@ for battery in /sys/class/power_supply/BAT?*; do *) exit 1 ;; esac # Will make a warn variable if discharging and low - [ "$status" = "Discharging" ] && [ "$capacity" -le 25 ] && warn="❗" + [ "$status" = "Discharging" ] && [ "$capacity" -lt 30 ] && warn="❗" # Prints the info printf "%s%s %d%%" "$warn" "$icon" "$capacity"; unset warn done && printf "\\n" @@ -55,11 +55,11 @@ done && printf "\\n" echo if [ $capacity -ge 80 ]; then echo "$BLOCK_COLOR_LEVEL1" -elif [ $capacity -ge 40 ]; then +elif [ $capacity -ge 60 ]; then echo "$BLOCK_COLOR_LEVEL2" -elif [ $capacity -ge 20 ]; then +elif [ $capacity -ge 40 ]; then echo "$BLOCK_COLOR_LEVEL3" -elif [ $capacity -ge 10 ]; then +elif [ $capacity -ge 20 ]; then echo "$BLOCK_COLOR_LEVEL4" else echo "$BLOCK_COLOR_LEVEL5" diff --git a/.local/bin/statusbar/i3weather b/.local/bin/statusbar/i3weather index 2d34149..dec12dd 100755 --- a/.local/bin/statusbar/i3weather +++ b/.local/bin/statusbar/i3weather @@ -1,26 +1,53 @@ #!/bin/sh -# i3block for displaying the current temperature, humidity and precipitation, if wttr.in i unavailable then WEATHER UNAVAILABLE will be displayed +# i3blocks weather module using wttr.in +# output is set to -- in case wttr.in is unreachable + +WTTR_CACHE_DIR="/tmp" +WTTR_CACHE="$WTTR_CACHE_DIR/wttr.in" +WTTR_TXT="$WTTR_CACHE_DIR/wttr.txt" +WTTR_LOCATION="Vasai" +WTTR_URL="https://wttr.in/$WTTR_LOCATION" + +notify() { + [ "$isUpdating" = 1 ] && + notify-send --replace-id=217534 "$@" +} + +err() { + printf "i3weather: %s\n" "$@" >&2 + notify "🛑 ERROR (i3weather)" "$*" + echo "⛅ -- " + exit 1 +} case "$BLOCK_BUTTON" in - '') ;; + '') true ;; 1) - $TERMINAL -e less -r ~/.cache/weather.txt & sleep 0.3 - i3-msg 'move to workspace "12: Weather"; workspace "12: Weather"' >/dev/null 2>&1 - ;; + [ -f "$WTTR_CACHE" ] || BLOCK_BUTTON=5 i3weather + st -c "dropdown_weather" \ + -g "$(wc -L < "$WTTR_TXT")x30" \ + -e less -r "$WTTR_CACHE" & sleep 0.3 ;; 2) $TERMINAL -e nvim "$0" ;; - *) notify-send "⛅ Refreshing weather info..." ;; + *) isUpdating=1; notify "⛅ Refreshing weather info..." ;; esac -HTTP_WEATHER="https://wttr.in/Vasai" -# weather="$(curl -s "$HTTP_WEATHER?format=%c%C++❄️+%t++☀️+%f++🌬️+%w")" -weather="$(curl -Ss "$HTTP_WEATHER?0&T&Q" | cut -c 16- | head -2 | - xargs echo "$(curl -s "$HTTP_WEATHER?format=%c")")" +# update cache files +res="$(curl -Ss "$WTTR_URL" > "$WTTR_CACHE" 2>&1)" || err "$res" +sed 's,\x1B\[[0-9;]*[a-zA-z],,g' "$WTTR_CACHE" > "$WTTR_TXT" +[ "$(wc -l "$WTTR_TXT" | cut -d' ' -f1)" -lt 20 ] && err "$(cat "$WTTR_TXT")" + +# get weather based on argument +case "$1" in + info) weather="$(curl -Ss "$WTTR_URL?format=%c%C" 2>&1)" ;; + cache) weather="$(sed -E '1,7!d; 3d; 6d; s/.{16}(.{,13}).*/\1/; s/\s//g' "$WTTR_TXT" | + sed -z 's/\n/:/; s/\n/ /g; s/\s*$//' 2>&1)" ;; + *) weather="$(curl -Ss "$WTTR_URL?format=%l:+%c+%t(%f)++%w++%p" 2>&1)" ;; +esac -if [ "$(echo "$weather" | grep -Ec "(Unknown|curl|HTML)")" -gt 0 ]; then - echo "WEATHER UNAVAILABLE" -else - echo "${weather:-⛅ -- }" -fi +# check for empty responses and errors +[ "$(echo "$weather" | grep -Ec "(Unknown|curl|HTML)")" -gt 0 ] && + err "$weather" || echo "${weather:-⛅ -- }" -curl -s "$HTTP_WEATHER" > ~/.cache/weather.txt +# End response when no error occurs +notify "✔️ Weather Updated." diff --git a/.local/bin/statusbar/sb-clock b/.local/bin/statusbar/sb-clock new file mode 100755 index 0000000..d652e92 --- /dev/null +++ b/.local/bin/statusbar/sb-clock @@ -0,0 +1,61 @@ +#!/bin/sh + +clock=$(date '+%I') + +# # emoji icons +# case "$clock" in +# "00") icon="🕛" ;; +# "01") icon="🕐" ;; +# "02") icon="🕑" ;; +# "03") icon="🕒" ;; +# "04") icon="🕓" ;; +# "05") icon="🕔" ;; +# "06") icon="🕕" ;; +# "07") icon="🕖" ;; +# "08") icon="🕗" ;; +# "09") icon="🕘" ;; +# "10") icon="🕙" ;; +# "11") icon="🕚" ;; +# "12") icon="🕛" ;; +# esac + +# nerd fonts clock +case "$clock" in + "00") icon="" ;; + "01") icon="" ;; + "02") icon="" ;; + "03") icon="" ;; + "04") icon="" ;; + "05") icon="" ;; + "06") icon="" ;; + "07") icon="" ;; + "08") icon="" ;; + "09") icon="" ;; + "10") icon="" ;; + "11") icon="" ;; + "12") icon="" ;; +esac + +# # nerd fonts clock filled +# case "$clock" in +# "00") icon="" ;; +# "01") icon="" ;; +# "02") icon="" ;; +# "03") icon="" ;; +# "04") icon="" ;; +# "05") icon="" ;; +# "06") icon="" ;; +# "07") icon="" ;; +# "08") icon="" ;; +# "09") icon="" ;; +# "10") icon="" ;; +# "11") icon="" ;; +# "12") icon="" ;; +# esac + +case $BLOCK_BUTTON in + 1) st -c "dropdown_calendar" -g 66x34 -e sh -c "cal -y --color=always|less" ;; + 2) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +date +"$icon %H:%M:%S %a %d.%m.%Y ✟ " diff --git a/.local/bin/text-preview b/.local/bin/text-preview deleted file mode 100755 index 4d0931d..0000000 --- a/.local/bin/text-preview +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -# A simple text previewer. -# Useful in certain cases when you don't want to use your glorified previewer -# and just see the raw text content of a processable document like a markdown -# file. - -[ -f "$1" ] && { - if command -v highlight >/dev/null; then - highlight --out-format=ansi -- "$1" - elif command -v bat >/dev/null; then - bat -- "$1" - else - cat -- "$1" - fi - exit -} - -if command -v eza >/dev/null; then - eza -alhF --group-directories-first --color=always --icons=always -- "$1" -else - ls -lhAF --group-directories-first --color=always -- "$1" -fi diff --git a/.local/bin/web/yth b/.local/bin/web/yth new file mode 100755 index 0000000..26cbe91 --- /dev/null +++ b/.local/bin/web/yth @@ -0,0 +1,19 @@ +#!/bin/sh + +[ -n "$YT_HISTFILE" ] || + export YT_HISTFILE="${XDG_STATE_HOME:-$HOME/.local/state}/yt_history.tsv" + +menu() { + case "$1" in + dmenu) tac "$YT_HISTFILE" | dmenu -l 30 ;; + *) + bat --color=always --language=tsv --style=plain "$YT_HISTFILE" | + fzf --ansi --tac \ + --delimiter '\t' --with-nth 2,3 \ + --header-first --header "YT History" \ + --preview="echo {1}" --preview-window="up,1" \ + --bind 'ctrl-y:execute-silent(printf "%s\n" {1} | xsel --clipboard)' ;; + esac +} + + menu "$@" | sed -E "s/\t.*\t.*$//" diff --git a/.local/bin/web/ytplaylist b/.local/bin/web/ytplaylist deleted file mode 100755 index 7bc9026..0000000 --- a/.local/bin/web/ytplaylist +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -# Useful when creating a directory of videos sequenced as per a youtube -# playlist. -# Run this script from from the root of a directory that contains all the media -# and metadata files. -# The playlist file is expected to be in 'playlist' directory within the root -# with .pl.txt extension. (playlist/PLAYLIST_NAME.pl.txt) -# The new playlist directory will be created in the current directory i.e. the -# root if no other destination is passed as the second argument. - -case "$1" in - '') echo "ytplaylist - build a directory of sequenced videos using a playlist file\n -USAGE:\n\tytplaylist <PLAYLIST_FILE> [DESTINATION_DIR] " >&2; exit ;; - playlist/*.pl.txt) ;; - *) - printf "%s" "Unconventional file path, contniue? [y/N] " - read -r ans - case "$ans" in y) ;; *) exit 1 ;; esac - ;; -esac - -playlist="$(readlink -f $1)" -i=1 -fpl "$playlist" | while read -r file; do - if [ -z "$file" ]; then - i=$(( $i + 1 )) - continue - fi - dir="$(dirname "$file")" - base="$(basename "$file")" - rsync -Pru --mkpath "$file" \ - "${2:-$(basename "${playlist%.pl.txt}")}/${dir#$(readlink -f "$PWD")}/$(printf "%02d" "$i") $base" -done diff --git a/.local/bin/web/ytv b/.local/bin/web/ytv index c6e9eec..697c86f 100755 --- a/.local/bin/web/ytv +++ b/.local/bin/web/ytv @@ -1,3 +1,16 @@ #!/bin/sh +case "$(echo "$PWD" | tr '[:upper:]' '[:lower:]')" in + *videos*|*movies*|*series*) ;; + *) + printf "Non standard path for video download, continue? [Y/n] " >&2 + + read -r arg + case "$arg" in + n|N) exit ;; + esac + echo + ;; +esac + yt-dlp "$@" --config ~/.config/yt-dlp/videos.conf |