From 466f820a99ad1c2eb7c72fef7de3e8f521824246 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sat, 18 Sep 2021 21:58:30 +0200 Subject: [PATCH] config/shell: update utils --- .config/shell/functions | 16 ++++++++++------ .local/bin/scripts/drag | 2 +- .local/bin/scripts/m | 9 +++++++++ .local/bin/scripts/mvk | 5 ----- README.org | 8 +++++--- 5 files changed, 25 insertions(+), 15 deletions(-) create mode 100755 .local/bin/scripts/m delete mode 100755 .local/bin/scripts/mvk diff --git a/.config/shell/functions b/.config/shell/functions index 705bd29..8c153c4 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -10,10 +10,11 @@ alias -g L="--color=always | ${PAGER:-less}" fi alias h='help' -compdef help=which +compdef help=man alias info='info --vi-keys' d() { + test "$1" != "-" -a ! -d "$1" -a $# -eq 1 || { cd "$@" && return } local query="$(zf "$@")" # First find out whether there is an obvious match # (score at least ten times above runner-up and score above 20) @@ -24,7 +25,8 @@ d() { fi | zfz)" } di() { - cd "$( ( zf "$@"; locz "$@" ) | zfz)" + test "$1" != "-" -a ! -d "$1" -a $# -eq 1 && local dir=$({ zf "$@"; locz "$@" } | zfz) + cd "${dir:-1}" } alias c=z alias v=edit @@ -118,7 +120,8 @@ edshell() { alias l="ls -l --almost-all --human-readable --group-directories-first --file-type" cd() { - test "$1" != "-" -a ! -d "$1" -a $# -eq 1 && dir=$(f --glob "$1*" "$DATA" --maxdepth 2 --type d --max-results 1) && + test "$1" != "-" -a ! -d "$1" -a $# -eq 1 && + dir=$(f --glob "$1*" "$DATA" --maxdepth 2 --type d --max-results 1) && test -n "$dir" && cd "$dir" && return builtin cd $1 && command ls --file-type --group-directories-first --color=always --format=vertical -w $COLUMNS | head -3 @@ -163,7 +166,7 @@ xo() { done } alias sqli='rlwrap sqlite3 -column -header -cmd .tables' -loci() { locate --ignore-case --basename --existing "$@" | command grep --extended-regexp --ignore-case --color=always $(echo "$|$@" | sed 's/ /|/g') | less -F } +loci() { locate --all --ignore-case --basename --existing "$@" | command grep --extended-regexp --ignore-case --color=always $(echo "$|$@" | sed 's/ /|/g') | less -F } alias loc='noglob loci' alias uloc='noglob sudo updatedb && loci' alias syslog='less +F /var/log/syslog' @@ -179,8 +182,8 @@ alias gdiff='git diff --word-diff=color --word-diff-regex=. --no-index' alias sc='sudo systemctl' alias sce='sudo systemctl enable --now' scs() { - systemctl --user status "$1" "*$1*" - sudo systemctl status "$1" "*$1*" + systemctl --user status "$1" "*$1*" || + sudo systemctl status "$1" "*$1*" } alias scu='systemctl --user' alias scue='systemctl --user enable --now' @@ -211,6 +214,7 @@ hex() { hexyl "$@" | "${PAGER:-less}" } # Applications alias dict="rdictcc -d $XDG_DATA_HOME/dictcc" #"(builtin cd $XDG_DATA_HOME/dictcc && rlwrap perl dictcc-helper.pl)" alias startMinecraftServer='curl https://ipinfo.io/ip | xclip -sel clip && cd ~/daten/games/sharedgames/minecraft/server && java -jar forge-1.12.2-14.23.5.2768-universal.jar -mx 8G' +alias delta="sc start openvpn-client@deltaPeak.service" test -d $HOME/.dropbox && dropbox_path="$(cat $HOME/.dropbox/info.json | grep -Po '"'"path"'"\s*:\s*"\K([^"]*)')" diff --git a/.local/bin/scripts/drag b/.local/bin/scripts/drag index e723505..5688ad3 100755 --- a/.local/bin/scripts/drag +++ b/.local/bin/scripts/drag @@ -1,3 +1,3 @@ #!/bin/sh # Start single all-in-one dragon-drag-and-drop with args or pwd -$(command which dragon 2>/dev/null || echo dragon-drag-and-drop) -x -a ${@:-.} +$(command which dragon 2>/dev/null || echo dragon-drag-and-drop) -x -a "${@:-.}" diff --git a/.local/bin/scripts/m b/.local/bin/scripts/m new file mode 100755 index 0000000..28dc92e --- /dev/null +++ b/.local/bin/scripts/m @@ -0,0 +1,9 @@ +#!/bin/sh -e +# Creates the last arg as directory (or its parent if not ending in a slash) +# and moves the preceding arguments into it. +# Automatically elevates if missing permissions. +for last; do true; done +! test -e "$1" && echo "$1 does not exist" && exit 1 +checkaccess -w "$last" || elevate=sudo +$elevate mkdir -p $(case "$last" in (*/) echo "$last";; (*) dirname "$last";; esac) +$elevate mv -n "$@" diff --git a/.local/bin/scripts/mvk b/.local/bin/scripts/mvk deleted file mode 100755 index f04d09e..0000000 --- a/.local/bin/scripts/mvk +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# Creates the last arg as directory (or its parent if not ending in a slash) and moves everything else into it -for last; do true; done -mkdir -p $(case "$last" in (*/) echo "$last";; (*) dirname "$last";; esac) -mv -n "$@" diff --git a/README.org b/README.org index 3c657fb..182127b 100644 --- a/README.org +++ b/README.org @@ -5,11 +5,11 @@ with the intention to move to Awesome soon. If you are looking to snag some of my handy tools, focus on [[.local/bin/scripts]] and [[.config/shell]]. -Among daily use are ~b~, ~edbin~, ~edconf~, ~edit~, ~yas~, ~walli~ +Among daily use are ~b~, ~edbin~, ~edconf~, ~edit~, ~help~, [[.config/shell/arch][~yas~]] and [[https://github.com/ajeetdsouza/zoxide][zoxide]]-based ~d~ / ~di~ which in turn use ~zfz~, ~zf~ & ~locz~. -~ex~, ~help~, ~moul~, ~mvk~, ~rpl~, ~s~, ~sd~, ~tl~ are also commonly used conveniences. +~ex~, ~m~, ~moul~, ~rpl~, ~s~, ~sd~, ~tl~, ~walli~ are also commonly used conveniences. ** Root I am trying to keep my home clean, but some files unfortunately cannot be moved. @@ -23,4 +23,6 @@ and configuration for ~less~ and ~fzf~. - ideavim, vifm, nvim :: vi-related tools - git, yadm :: version control ** .local -- [[.local/bin/scripts][scripts]] :: lots of useful scripts, most have a short documentation header - including many essential git scripts +- [[.local/bin/scripts][scripts]] :: lots of useful scripts, + most have a short documentation header - + including many essential git scripts