summaryrefslogtreecommitdiff
path: root/.local/bin
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/desktop/brightness1
-rwxr-xr-x.local/bin/desktop/setdp4
-rwxr-xr-x.local/bin/desktop/windowshot3
-rwxr-xr-x.local/bin/desktop/zbarscreen3
-rwxr-xr-x.local/bin/desktop/zbarwindow3
-rwxr-xr-x.local/bin/development/font2svg (renamed from .local/bin/shorts/font2svg)0
-rwxr-xr-x.local/bin/development/gitpush6
-rwxr-xr-x.local/bin/development/nx85
-rwxr-xr-x.local/bin/fgrp31
-rwxr-xr-x.local/bin/frg70
-rwxr-xr-x.local/bin/preview4
-rwxr-xr-x.local/bin/shortcuts33
-rwxr-xr-x.local/bin/shorts/gi6
-rwxr-xr-x.local/bin/shorts/mailsyncd6
-rwxr-xr-x.local/bin/shorts/rep3
-rwxr-xr-x.local/bin/shorts/windowshot6
16 files changed, 121 insertions, 143 deletions
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/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/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 <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/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 <prompt-query>" \
+ --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/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"