From cb110575144beb4125fd1d8204c8204e6bca280f Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 7 Aug 2023 18:59:08 +0200 Subject: [goo] added option to give search query as second paramater I noticed by mistake sometimes I would type the query already. --- config/essentials/zsh/functions.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 671e6fb..053ce8e 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -39,9 +39,9 @@ nnn() { test -z "$NNNLVL" && /usr/bin/nnn "$@" || exit } ranger() { test -z "$RANGER_LEVEL" && /usr/bin/ranger "$@" || exit } # googoo aliases -ff () { goo f "$1" | fzf } -fd () { goo d "$1" | fzf } -fdf () { goo f "$1" | fzf | xargs -I {} dirname "{}" } +ff () { goo f "$1" } +fd () { goo d "$1" } +fdf () { goo f "$1" | xargs -I {} dirname "{}" } o () { f="$(ff $1)" -- cgit v1.2.3 From b3f42fec8739d1d23ec6d64ff35c9db022c5adca Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 13 Aug 2023 20:15:52 +0200 Subject: [googoo] removed functions and updated behaviour removed functions that where unneed as they were only called once, changed behaviour to not implement fzf in goo but in the functions itself, this makes goo easier to implement in other commands. Also ported over the funcitonality of setting the query with the first argument --- bin/common/goo | 7 +------ config/essentials/zsh/functions.zsh | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/bin/common/goo b/bin/common/goo index 2a5faad..a56cbaf 100755 --- a/bin/common/goo +++ b/bin/common/goo @@ -15,14 +15,9 @@ VisualParadigm intellij arduino15" -if [ -n "$2" ] -then - [ -d "$2" ] && dest="$2" || opt="-q $2" -fi - for dir in $exclude; do dirs="$dirs -name \"$dir\" -o " done cmd="find ${dest:-$HOME} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" -eval "$cmd" 2>/dev/null | fzf $opt +eval "$cmd" 2>/dev/null diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 053ce8e..c4999db 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -39,23 +39,30 @@ nnn() { test -z "$NNNLVL" && /usr/bin/nnn "$@" || exit } ranger() { test -z "$RANGER_LEVEL" && /usr/bin/ranger "$@" || exit } # googoo aliases -ff () { goo f "$1" } -fd () { goo d "$1" } -fdf () { goo f "$1" | xargs -I {} dirname "{}" } +_googoo_fzf_opt () +{ + if [ "$1" ] + then + [ -d "$1" ] && dest="$1" || opt="-q $1" + fi +} o () { - f="$(ff $1)" + _googoo_fzf_opt "$1" + f="$(goo f "dest" | fzf $opt)" test "$1" && shift - test -n "$f" && $EDITOR $@ "$f" + test -f "$f" && $EDITOR $@ "$f" } go () { - d="$(fd $1)" + _googoo_fzf_opt "$1" + d="$(goo d "$dest" | fzf $opt)" test -d "$d" && cd "$d" } ogo () { - d="$(fdf $1)" + _googoo_fzf_opt "$1" + d="$(dirname "$(goo f "$dest")" | fzf $opt)" test -d "$d" && cd "$d" } -- cgit v1.2.3 From 02a5c5ddf55986666335e2d5a16c4635f0b6ca80 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 13 Aug 2023 20:17:59 +0200 Subject: [functions] use grouping in calc, added psgrep --- config/essentials/zsh/functions.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index c4999db..3c5f11f 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -76,7 +76,13 @@ ipc () fi } -calc () { echo "$@" | bc -l } +calc () { echo "$@" | bc -l | numfmt --grouping; } + +psgrep () +{ + [ $# -eq 0 ] && return 1 + pgrep "$@" | xargs ps +} unique () { local f -- cgit v1.2.3 From e1893b1b31503adaa2c2484b57a5d7a4a5d0516c Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 14 Aug 2023 21:37:08 +0200 Subject: [googoo] fixed destination argument not working --- bin/common/goo | 2 +- config/essentials/zsh/functions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/bin/common/goo b/bin/common/goo index a56cbaf..cfd03ec 100755 --- a/bin/common/goo +++ b/bin/common/goo @@ -18,6 +18,6 @@ arduino15" for dir in $exclude; do dirs="$dirs -name \"$dir\" -o " done -cmd="find ${dest:-$HOME} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" +cmd="find ${2:-$HOME} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" eval "$cmd" 2>/dev/null diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 3c5f11f..e0eeb45 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -49,7 +49,7 @@ _googoo_fzf_opt () o () { _googoo_fzf_opt "$1" - f="$(goo f "dest" | fzf $opt)" + f="$(goo f "$dest" | fzf $opt)" test "$1" && shift test -f "$f" && $EDITOR $@ "$f" } -- cgit v1.2.3 From edf8bc8432bb17854b5ef5667864ed58550956d1 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 15 Aug 2023 12:06:44 +0200 Subject: [functions.zsh] changed function name format --- config/essentials/zsh/functions.zsh | 60 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index e0eeb45..dee883f 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -1,6 +1,6 @@ #!/bin/zsh -die () +die() { echo "$@" >&2 } @@ -39,34 +39,34 @@ nnn() { test -z "$NNNLVL" && /usr/bin/nnn "$@" || exit } ranger() { test -z "$RANGER_LEVEL" && /usr/bin/ranger "$@" || exit } # googoo aliases -_googoo_fzf_opt () +_googoo_fzf_opt() { if [ "$1" ] then [ -d "$1" ] && dest="$1" || opt="-q $1" fi } -o () +o() { _googoo_fzf_opt "$1" f="$(goo f "$dest" | fzf $opt)" test "$1" && shift test -f "$f" && $EDITOR $@ "$f" } -go () +go() { _googoo_fzf_opt "$1" d="$(goo d "$dest" | fzf $opt)" test -d "$d" && cd "$d" } -ogo () +ogo() { _googoo_fzf_opt "$1" d="$(dirname "$(goo f "$dest")" | fzf $opt)" test -d "$d" && cd "$d" } -ipc () +ipc() { if [[ "$(ip link show eno1 | awk -F, 'NR=1 {print $3}')" == "UP" ]] then @@ -76,22 +76,20 @@ ipc () fi } -calc () { echo "$@" | bc -l | numfmt --grouping; } - -psgrep () +psgrep() { [ $# -eq 0 ] && return 1 pgrep "$@" | xargs ps } -unique () { +unique() { local f f="$(mktemp)" awk '!x[$0]++' "$1" > "$f" mv "$f" "$1" } -clip () { +clip() { if [ "$WAYLAND_DISPLAY" ] then echo -n "$@" | wl-copy @@ -100,7 +98,7 @@ clip () { fi } -unzipp () { +unzipp() { file=$1 shift unzip $file $@ || exit 1 @@ -108,18 +106,18 @@ unzipp () { } # fix long waiting time -__git_files () { +__git_files() { _wanted files expl 'local files' _files } -esc () { +esc() { $EDITOR "$(which $1)" } -delfile () { +delfile() { curl "${2:-https://upfast.cronyakatsuki.xyz/delete/$1}" } -upfile () { +upfile() { curl -F "file=@\"$1\"" ${2:-https://upfast.cronyakatsuki.xyz} } @@ -177,7 +175,7 @@ function git_develop_branch() { } # gpg backup -gpg_backup () +gpg_backup() { gpg --export-secret-keys --armor > private.asc gpg --export --armor > public.asc @@ -186,7 +184,7 @@ gpg_backup () shred -uz {public,private,trust}.asc } -gpg_import () +gpg_import() { tar xf $1 shred -uz $1 @@ -196,29 +194,29 @@ gpg_import () shred -uz {public,private,trust}.asc } -ngenable () +ngenable() { ln -sf /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/ } -vbsr () +vbsr() { vboxmanage snapshot "$1" restore "$2" && vboxmanage startvm "$1" || vboxmanage controlvm "$1" poweroff } -vbsrr () +vbsrr() { vbsr "$1" "$2" sleep 3 vbsr "$1" "$2" } -vbst () +vbst() { vboxmanage snapshot "$1" take "$2" } -pacsize () +pacsize() { if test -n "$1"; then packages="$@" @@ -232,7 +230,7 @@ pacsize () expac '%m %n' - | numfmt --to=iec-i --suffix=B --format="%.2f" } -pkbs () +pkbs() { pkgfile -b "$1" | tee /dev/stderr | doas pacman -S - } @@ -247,7 +245,7 @@ mime-default () die "Done." } -addedkeys () { +addedkeys() { find ~/.ssh -iname "*.pub" | while read key do local fingerprint="$(ssh-keygen -lf "$key" 2>/dev/null)" @@ -258,7 +256,7 @@ addedkeys () { done | sed "s,$HOME/.ssh/,," } -fpass () { +fpass() { find $HOME/.password-store -type f -not -path ".git" | grep "\.gpg$" | sed "s,$HOME/.password-store/,,;s,\.gpg$,," | @@ -266,22 +264,22 @@ fpass () { xargs pass show -c } -oclip () +oclip() { printf "\033]52;c;$(echo -n "$@" | base64)\a" } -sms () +sms() { ssh phone sendmsg "$1" "'$2'" } -trcp () +trcp() { scp "$1" db:/media/basilisk/downloads/transmission/torrents/ } -muttmail () +muttmail() { die -n "email set: " ls $HOME/.config/mutt/configs | @@ -292,7 +290,7 @@ muttmail () read && mutt } -resize () +resize() { test $# -lt 2 && printf "usage: %s [out]\n" "$0" >&2 && -- cgit v1.2.3 From dd75534e1878d7934d0a402a70e20d24226fcd8e Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 15 Aug 2023 12:07:02 +0200 Subject: [functions.zsh] renamed die to log --- config/essentials/zsh/functions.zsh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index dee883f..0d4b8a5 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -1,9 +1,7 @@ #!/bin/zsh -die() -{ - echo "$@" >&2 -} +log() { >&2 printf '%s' "$@"; } +logn() { >&2 printf '%s\n' "$@"; } awnk() { awk "{print \$$1}" -- cgit v1.2.3 From 2321b913f89f2bc678c8931db05e0eb5898d7191 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 15 Aug 2023 12:09:07 +0200 Subject: [functions.zsh] added ginit function to init a dir on db remote --- config/essentials/zsh/functions.zsh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 0d4b8a5..6c2437f 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -138,16 +138,24 @@ sgd () { unset d } -# Git functions +ginit() +{ + [ "$1" ] || return 1 + ssh db /var/git/initdir.sh "$1" + git remote add origin git@db:"$1.git" + git push --set-upstream origin $(git_current_branch) +} + # Returns current branch -function git_current_branch() +git_current_branch() { command git rev-parse --git-dir &>/dev/null || return git branch --show-current } # Check if main exists and use instead of master -function git_main_branch() { +git_main_branch() +{ command git rev-parse --git-dir &>/dev/null || return local ref for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default}; do -- cgit v1.2.3 From 0ea5e7a97b7ccba919d5c495e3e328b30cec9e03 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 15 Aug 2023 15:08:46 +0200 Subject: [functions.zsh] removed unecessary tests --- config/essentials/zsh/functions.zsh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 6c2437f..eb776f0 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -54,14 +54,20 @@ o() go() { _googoo_fzf_opt "$1" - d="$(goo d "$dest" | fzf $opt)" - test -d "$d" && cd "$d" + cd "$(goo d "$dest" | fzf $opt)" } ogo() { _googoo_fzf_opt "$1" - d="$(dirname "$(goo f "$dest")" | fzf $opt)" - test -d "$d" && cd "$d" + cd "$(dirname "$(goo f "$dest")" | fzf $opt)" +} +dgo() +{ + cd "$(goo d | fzf --filter "$@" | head -n 1)" +} +open() +{ + $EDITOR "$(goo f | fzf --filter "$@" | head -n 1)" } ipc() -- cgit v1.2.3 From c9dec781ad79c0345c7d2d98ab59de5d4f858ba7 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Fri, 25 Aug 2023 00:32:08 +0200 Subject: [functions.zsh] use log(n) --- config/essentials/zsh/functions.zsh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index eb776f0..1682315 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -20,7 +20,7 @@ nvf() { local match="$(grep -m1 "$1$" "$cache" 2> /dev/null)" if test ! -f "$match" then - die "resetting cache..." + logn "resetting cache..." match="$(goo | tee "$cache" | grep -m 1 "$1$" 2> /dev/null)" # # Alternative: # match="$(goo | grep -m 1 "$1" 2> /dev/null | tee -a | "$cache")" @@ -29,7 +29,7 @@ nvf() { then $EDITOR "$match" && return else - die "no match." && return 1 + logn "no match." && return 1 fi } @@ -249,12 +249,12 @@ pkbs() mime-default () { - die "Setting '$1' as default for its mimetypes" + logn "Setting '$1' as default for its mimetypes" grep "MimeType=" /usr/share/applications/"$1" | cut -d '=' -f 2- | tr ';' '\n' | xargs -I {} xdg-mime default "$1" "{}" - die "Done." + logn "Done." } addedkeys() { @@ -293,12 +293,12 @@ trcp() muttmail() { - die -n "email set: " + log "email set: " ls $HOME/.config/mutt/configs | fzf | tee /dev/stderr | xargs -I {} ln -sf "$HOME/.config/mutt/configs/{}" $HOME/.config/mutt/muttrc - die -n 'Press [Enter to login]' + log 'Press [Enter to login]' read && mutt } @@ -309,3 +309,5 @@ resize() return 1 convert -resize $1^ -gravity center -crop $1+0+0 -- "$2" "${3:-$1}" } + +rln() { ln -s "$(readlink -f "$1")" "$2"; } -- cgit v1.2.3 From 0b5f4fbc66bc3ba5a1717f70a9b4ae5fb542742c Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Fri, 25 Aug 2023 00:32:46 +0200 Subject: [functions.zsh] fixed typo in ogo --- config/essentials/zsh/functions.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 1682315..7a94207 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -59,7 +59,7 @@ go() ogo() { _googoo_fzf_opt "$1" - cd "$(dirname "$(goo f "$dest")" | fzf $opt)" + cd "$(dirname "$(goo f "$dest" | fzf $opt)")" } dgo() { -- cgit v1.2.3 From 333aaf38c66a1e4ba41d3acea38b21613c0075b2 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 27 Aug 2023 12:53:48 +0200 Subject: [functions] grouped oneliners together --- config/essentials/zsh/functions.zsh | 50 ++++++++++--------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 7a94207..22a8fbe 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -3,18 +3,11 @@ log() { >&2 printf '%s' "$@"; } logn() { >&2 printf '%s\n' "$@"; } -awnk() { - awk "{print \$$1}" -} - vmp() { col -b | \ vim -MR \ -c 'set ft=man nolist nonu nornu' } -vimh() { - vim -c "help $1" -c 'call feedkeys("\o")' -} nvf() { local cache="$HOME/.cache/nvf" local match="$(grep -m1 "$1$" "$cache" 2> /dev/null)" @@ -61,14 +54,17 @@ ogo() _googoo_fzf_opt "$1" cd "$(dirname "$(goo f "$dest" | fzf $opt)")" } -dgo() -{ - cd "$(goo d | fzf --filter "$@" | head -n 1)" -} -open() -{ - $EDITOR "$(goo f | fzf --filter "$@" | head -n 1)" -} + +# Onelineres +awnk() { awk "{print \$$1}"; } +vimh() { vi -c "help $1" -c 'call feedkeys("\o")'; } +dgo() { cd "$(goo d ~ | fzf --filter "$@" | head -n 1)"; } +open() { $EDITOR "$(goo f ~ | fzf --filter "$@" | head -n 1)"; } +pkbs() { pkgfile -b "$1" | tee /dev/stderr | doas pacman -S -; } +oclip() { printf "\033]52;c;$(echo -n "$@" | base64)\a"; } +sms() { ssh phone sendmsg "$1" "'$2'"; } +trcp() { scp "$1" db:/media/basilisk/downloads/transmission/torrents/; } +rln() { ln -s "$(readlink -f "$1")" "$2"; } ipc() { @@ -125,7 +121,8 @@ upfile() { curl -F "file=@\"$1\"" ${2:-https://upfast.cronyakatsuki.xyz} } -sgd () { +# git +sgd() { d="$PWD" find $HOME/src -maxdepth 1 -mindepth 1 -type d | while read -r dir @@ -242,10 +239,6 @@ pacsize() expac '%m %n' - | numfmt --to=iec-i --suffix=B --format="%.2f" } -pkbs() -{ - pkgfile -b "$1" | tee /dev/stderr | doas pacman -S - -} mime-default () { @@ -276,21 +269,6 @@ fpass() { xargs pass show -c } -oclip() -{ - printf "\033]52;c;$(echo -n "$@" | base64)\a" -} - -sms() -{ - ssh phone sendmsg "$1" "'$2'" -} - -trcp() -{ - scp "$1" db:/media/basilisk/downloads/transmission/torrents/ -} - muttmail() { log "email set: " @@ -309,5 +287,3 @@ resize() return 1 convert -resize $1^ -gravity center -crop $1+0+0 -- "$2" "${3:-$1}" } - -rln() { ln -s "$(readlink -f "$1")" "$2"; } -- cgit v1.2.3