From 4f75e71ff7b81ae221ca2d4f94c88c74a9e870fe Mon Sep 17 00:00:00 2001 From: xerus2000 <27jf@pm.me> Date: Mon, 16 Nov 2020 12:29:31 +0100 Subject: [PATCH] config/shell: update aliases --- .config/shell/functions | 13 +++++++++++-- .local/bin/b | 24 ++++++++---------------- .local/bin/ex | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 18 deletions(-) create mode 100755 .local/bin/ex diff --git a/.config/shell/functions b/.config/shell/functions index a5d8c1c..ab005c8 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -13,6 +13,13 @@ ulimit -c unlimited # Enable core dumps which lsb_release >/dev/null && export DIST=$(lsb_release --id | cut -d' ' -f2) || true alias info='info --vi-keys' +unalias rd +rd() { + test -d "$1" && find "$1" -type d -empty -delete || rm "$@" +} +rr() { mv "$@" /tmp } + +alias logoff="loginctl terminate-user $USER" # Some aliases alias editgrub='sudoedit /etc/default/grub && sudo update-grub' @@ -20,7 +27,10 @@ alias editenv='sudoedit /etc/environment' editright() { test ! -f "$1" && ( mkdir -p $(dirname "$1") || sudo mkdir -p $(dirname "$1") ) echo "Editing $1..." - (test -w "$1" || (test ! -f "$1" && test -w $(dirname "$1"))) && $EDITOR "$1" || sudoedit "$1" + if test -w "$1" || (test ! -f "$1" && test -w $(dirname "$1")) + then $EDITOR "$1" + else sudoedit "$1" + fi } # Underline arg @@ -89,7 +99,6 @@ alias twtest='( TIMEWARRIORDB=/tmp/timewarriordb && mv ${TIMEWARRIORDB} /tmp/twd # Quick shortcuts alias c='clear' alias v='editright' -alias rm='rm -d' alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G' alias lar='last | tac' diff --git a/.local/bin/b b/.local/bin/b index 7eacec8..8c1fd6d 100755 --- a/.local/bin/b +++ b/.local/bin/b @@ -1,18 +1,10 @@ #!/bin/sh - # Show type & contents of given files or PWD - -#if test $# -gt 1 -#then -# for arg in "$@"; do -# b --pager=never "$arg" -# done -#else - arg=$(test $# -gt 0 && echo "${@:-1}" || echo .) - file $arg | grep -v --color=never directory - case "$(file --dereference --mime $arg)" in - *inode/directory*) ls -l --color=auto --almost-all --human-readable --group-directories-first --file-type --dereference-command-line "$@";; - *binary) ;; - *) bat --style header "$@";; - esac -#fi +for last; do true; done +last=${last:-.} +file "$last" | grep -v --color=never directory +case "$(file --dereference --mime "$last")" in + *inode/directory*) ls -l --color=auto --human-readable --group-directories-first --file-type --dereference-command-line --all --reverse "$@";; + *binary) ;; + *) bat --style header "$@";; +esac diff --git a/.local/bin/ex b/.local/bin/ex new file mode 100755 index 0000000..c4539eb --- /dev/null +++ b/.local/bin/ex @@ -0,0 +1,24 @@ +#!/bin/sh +# ex - archive extractor +# usage: ex +if test -f $1 && test -r $1; then + case $1 in + *.tar.bz2) tar xjf $1 ;; + *.tar.gz) tar xzf $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xf $1 ;; + *.tbz2) tar xjf $1 ;; + *.tgz) tar xzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1;; + *.7z) 7z x $1 ;; + *.deb) ar x $1 ;; + *.tar.xz) tar xf $1 ;; + *.tar.zst) unzstd $1 ;; + *) echo "'$1' cannot be extracted via ex()" ;; + esac +else + echo "'$1' is not a readable file" +fi