From 0d397e4d3d204a1e016c0863815f0b5dc516c46b Mon Sep 17 00:00:00 2001 From: Vikas Kushwaha Date: Wed, 21 May 2025 14:30:00 +0530 Subject: added some new scripts and cleaned up nvim directory --- .local/bin/desktop/brightness | 1 + .local/bin/desktop/setdp | 4 +- .local/bin/desktop/windowshot | 3 ++ .local/bin/desktop/zbarscreen | 3 ++ .local/bin/desktop/zbarwindow | 3 ++ .local/bin/development/font2svg | 3 ++ .local/bin/development/gitpush | 6 --- .local/bin/development/nx | 85 ++--------------------------------------- .local/bin/fgrp | 31 --------------- .local/bin/frg | 70 +++++++++++++++++++++++++++++++++ .local/bin/preview | 4 +- .local/bin/shortcuts | 33 +++++++++------- .local/bin/shorts/font2svg | 3 -- .local/bin/shorts/gi | 6 +++ .local/bin/shorts/mailsyncd | 6 +++ .local/bin/shorts/rep | 3 ++ .local/bin/shorts/windowshot | 6 --- 17 files changed, 124 insertions(+), 146 deletions(-) create mode 100755 .local/bin/desktop/windowshot create mode 100755 .local/bin/desktop/zbarscreen create mode 100755 .local/bin/desktop/zbarwindow create mode 100755 .local/bin/development/font2svg delete mode 100755 .local/bin/fgrp create mode 100755 .local/bin/frg delete mode 100755 .local/bin/shorts/font2svg create mode 100755 .local/bin/shorts/gi create mode 100755 .local/bin/shorts/mailsyncd create mode 100755 .local/bin/shorts/rep delete mode 100755 .local/bin/shorts/windowshot (limited to '.local') 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/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/font2svg b/.local/bin/development/font2svg new file mode 100755 index 0000000..539972d --- /dev/null +++ b/.local/bin/development/font2svg @@ -0,0 +1,3 @@ +#!/bin/sh + +fontforge -c "import fontforge; fontforge.open('$1').generate('${1%.*}.svg')" 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/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 - -int main() -{ - printf("Hello\n"); - - return 0; -} -EOF -} - - -new_cpp_file() { - cat << EOF > "$1" -#include - -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/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/frg b/.local/bin/frg new file mode 100755 index 0000000..97f703a --- /dev/null +++ b/.local/bin/frg @@ -0,0 +1,70 @@ +#!/bin/sh + +# https://junegunn.github.io/fzf/tips/ripgrep-integration/#6-bind-enter-to-become-action + +help() { echo "frg - grep with fzf + +USAGE: + fgrp [OPTION]... PATTERN + +OPTIONS: + -r real time grepping in fzf prompt + -h show this help message"; } + +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" + +if command -v rg >/dev/null; then + GREP_CMD="rg --smart-case --column --color=always" +elif command -v git >/dev/null; then + GREP_CMD="git grep -I --ignore-case --column --color=always" +else + GREP_CMD="grep -Rnsi --exclude-dir=.git --color=always" +fi + +RELOAD="reload($GREP_CMD {q} || :)" + +OPENER=' + # update history + sed -i \\\|^{q}$\|d "$FZF_HIST" + echo {q} >> "$FZF_HIST" + + 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 + ' + +query="$*" + +fzf() { $GREP_CMD "$query" | command fzf "$@" \ + --ansi --multi --header-first \ + --history="$FZF_HIST" \ + --bind "enter:execute($OPENER)" \ + --bind "ctrl-o:become($OPENER)" \ + --bind 'ctrl-v:toggle-preview,ctrl-space:toggle-preview' \ + --bind "ctrl-r:reload($GREP_CMD '$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: $GREP_CMD " \ + --bind "change:$RELOAD" +else + fzf --header "COMMAND: $GREP_CMD '$query'" +fi diff --git a/.local/bin/preview b/.local/bin/preview index 235f0e0..68eec32 100755 --- a/.local/bin/preview +++ b/.local/bin/preview @@ -19,7 +19,7 @@ case "$1" in *.html) w3m -dump "$1" ;; *.md) glow "$1" ;; # *.vim) highlight --syntax=vim --replace-tabs=2 -- "$1" ;; - *.js|*.vim|*.lua) highlight -- "$1" ;; + *.js*|*.ts*|*.vim|*.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" ;; @@ -47,7 +47,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..af3fe5b 100755 --- a/.local/bin/shortcuts +++ b/.local/bin/shortcuts @@ -1,25 +1,28 @@ #!/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(\"hash -d %s=%s\n\", \$1, \$2) >> \"$zsh_named_dirs\" + printf(\"c%s='cd %s && ls -A' \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" + printf(\"d%s=\42%s\42 \\\\\n\", \$1, \$2) >> \"$shell_env_shortcuts\" + printf(\"hash -d d%s=%s\n\", \$1, \$2) >> \"$zsh_named_dirs\" printf(\"map c%s :cd %s\n\", \$1, \$2) >> \"$lf_shortcuts\" - printf(\"cmap ;%s %s\n\", \$1, \$2) >> \"$vim_shortcuts\" + printf(\"cmap ;d%s %s\n\", \$1, \$2) >> \"$vim_shortcuts\" + printf(\"imap ;d%s %s\n\", \$1, \$2) >> \"$vim_shortcuts\" } " @@ -27,9 +30,11 @@ eval "echo \"$(cat "$bmfiles")\"" | awk -F'\t' " !/^\s*#/ && !/^\s*$/ { gsub(\"\\\s*#.*$\", \"\"); - printf(\"alias %s='\$EDITOR %s'\n\", \$1, \$2) >> \"$shell_shortcuts\" - printf(\"hash -d %s=%s\n\", \$1, \$2) >> \"$zsh_named_dirs\" + printf(\"e%s='\$EDITOR %s' \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" + printf(\"export f%s=\42%s\42 \\\\\n\", \$1, \$2) >> \"$shell_env_shortcuts\" + printf(\"hash -d f%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\" + printf(\"cmap ;f%s %s\n\", \$1, \$2) >> \"$vim_shortcuts\" + printf(\"imap ;f%s %s\n\", \$1, \$2) >> \"$vim_shortcuts\" } " diff --git a/.local/bin/shorts/font2svg b/.local/bin/shorts/font2svg deleted file mode 100755 index 539972d..0000000 --- a/.local/bin/shorts/font2svg +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -fontforge -c "import fontforge; fontforge.open('$1').generate('${1%.*}.svg')" diff --git a/.local/bin/shorts/gi b/.local/bin/shorts/gi new file mode 100755 index 0000000..d78ff99 --- /dev/null +++ b/.local/bin/shorts/gi @@ -0,0 +1,6 @@ +#!/bin/sh + +# gi - edit the Git Ignore file of current repo + +TOPLEVEL="$(git rev-parse --show-toplevel)" || exit +find "$TOPLEVEL" -name ".gitignore" | xargs -r nvim -p diff --git a/.local/bin/shorts/mailsyncd b/.local/bin/shorts/mailsyncd new file mode 100755 index 0000000..4b51c45 --- /dev/null +++ b/.local/bin/shorts/mailsyncd @@ -0,0 +1,6 @@ +#!/bin/sh + +while true; do + mailsync + sleep 5m +done 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/shorts/windowshot b/.local/bin/shorts/windowshot deleted file mode 100755 index c654cc7..0000000 --- a/.local/bin/shorts/windowshot +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -image="${XDG_PICTURES_DIR:-$HOME/Pictures}/xwindow.jpg" -import -window "$(xdotool selectwindow)" "$image" -# dragon-drop --and-exit "$image" -xclip -sel clipboard -t image/png -i "$image" -- cgit v1.2.3