diff --git a/home/user/.config/bash/aliases b/home/user/.config/bash/aliases index 0bed927..f35eac9 100644 --- a/home/user/.config/bash/aliases +++ b/home/user/.config/bash/aliases @@ -1,4 +1,4 @@ - +_f() {} # colors if [ -x "$(command -v dircolors)" ]; then @@ -16,6 +16,7 @@ alias ll='ls -lhFv' alias la='ls -AFv' alias lla='ls -lhFAv' alias ll.='ls -lhFAv --ignore="*"' +alias lsl='_f() { ls -lhFA --color=always "${1:=.}" | tail -n +2 | bash -c "$PAGER" }; _f' alias _='sudo' @@ -27,16 +28,16 @@ alias mkdir='mkdir -pv' alias cd..='cd ..' alias ..='cd ..' alias ...='cd ../..' +alias ....='cd ../../..' alias .3='cd ../../..' +alias cl='_f() { cd "${1:=$HOME}" && ls -F --color=auto }; _f' alias path='echo -e ${PATH//:/\\n}' -alias history='history 0' - # shorts alias c='clear' alias q='exit 0' -alias h='history' +alias h='history 0' alias j='jobs -l' # utils @@ -45,7 +46,6 @@ alias genpass="openssl rand -base64 12" alias gensalt="dd if=/dev/urandom count=16 2>/dev/null | sha256sum | head -c 64" alias diff='colordiff' alias tar-it='tar -czf "../${PWD##*/}.tar.gz" .' -alias mcdtmp='cd "$(mktemp -d)"' # time @@ -55,7 +55,6 @@ alias cal='cal -m' # vim alias svi="sudo -E nvim" -alias edit=nvim # net alias ports='ss -tlnp' @@ -68,7 +67,7 @@ alias weather='curl -4 wttr.in/$(cat) 2>/dev/null | head -n -1' # weather by ci # starts web server alias www='python3 -m http.server 8000' -# hard +# hardware alias reboot='sudo /sbin/reboot' alias poweroff='sudo /sbin/poweroff' alias suspend='sudo systemctl suspend' @@ -76,8 +75,6 @@ alias halt='sudo /sbin/halt' alias shutdown='sudo /sbin/shutdown now' alias meminfo='free -mlth' -alias psmem='ps auxf | sort -nr -k 4 | bash -c "$PAGER"' -alias music='mplayer -shuffle ~/Music/*.mp3' if [[ "$OSTYPE" == "linux-gnu"* ]]; then alias wake='((speaker-test -t sine -f 400 &>/dev/null)& local pid=$! ;sleep 0.2s; kill -9 $pid) &>/dev/null' diff --git a/home/user/.config/bash/functions b/home/user/.config/bash/functions index b32eade..5045512 100644 --- a/home/user/.config/bash/functions +++ b/home/user/.config/bash/functions @@ -1,5 +1,4 @@ - -_sod () { +_sod() { if [ -d "$1" ] && [ -n "$(ls "$1"/ 2>/dev/null)" ]; then for FILENAME in $(ls "$1"/ | sort -n) do @@ -8,10 +7,8 @@ _sod () { fi } -lt () { - local DIR - test -z "$1" && DIR="." || DIR="$1" - du -h "$DIR" 2>/dev/null | sort -h | tac +lt() { + du -h "${1:=.}" 2>/dev/null | sort -h | tac } destroy() { @@ -23,42 +20,10 @@ destroy() { [[ $response == [yY] ]] && shred -zun 25 "$1" } -lsl () { - - local DIR - DIR="$1" - - if [ -z "$1" ]; then - DIR="$(pwd)" - fi - - ls -lhFA --color=always "${DIR}" | tail -n +2 | bash -c "$PAGER" -} - workon() { - local ENV_NAME - ENV_NAME="$1" - - if [ -z "$1" ]; then - ENV_NAME=$(basename "$(pwd)") - fi - - source /opt/pythonenv/"$ENV_NAME"/bin/activate + source /opt/pythonenv/"${1:=$(basename $PWD)}"/bin/activate } - -cl() { - local DIR - DIR="$*" - - if [ $# -lt 1 ]; then - DIR="$HOME" - fi - - cd "${DIR}" && ls -F --color=auto -} - - py() { if [[ -z "$@" && -x "$(command -v ipython 2>/dev/null)" ]]; then ipython -i -c "q = exit" @@ -67,20 +32,10 @@ py() { fi } - ve() { - local venv_name - - if [ -n "$1" ]; then - venv_name="$1" - else - venv_name="venv" - fi - - python3 -m virtualenv "$venv_name" && . "$venv_name/bin/activate" + python3 -m virtualenv "${1:=venv}" && . "${1:=venv}/bin/activate" } - va() { local activate_venv @@ -101,7 +56,7 @@ va() { } -extract () { +extract() { if [ -z "$1" ]; then # if string non-zero # display usage if no parameters given echo "extract: error: usage: extract ." @@ -146,9 +101,12 @@ extract () { } -mcd () { - test -z "$1" && return 1 - mkdir -p "$1" && cd "$1" || return +mcd() { + if [ -z "$1" ]; then + cd "$(mktemp -d)" + else + mkdir -p "$1" && cd "$1" + fi } @@ -174,7 +132,7 @@ vpn() { ) } -# setup ssh tunnel to $1 as proxy +# setup ssh tunnel to server $1 as proxy toggle-proxy() { if [ -z "$http_proxy" ]; then export {http,https,ftp,rsync}_proxy="socks5://127.0.0.1:8888" @@ -200,26 +158,10 @@ split-file() { (mkdir "$1.splitted" && cd "$1.splitted" && split -d -b "$_size" "../$1") } -# returns url to code previewer -rayso() { - local CODE TITLE - - if [[ -n "$1" ]]; then - CODE="$(cat "$1" | base64)" - TITLE="$(basename "$1")" - else - CODE="$(cat | base64)" - TITLE="Code" - fi - - echo "https://ray.so/?colors=candy&background=true&darkMode=true&padding=64&title=${TITLE}&code=${CODE}&language=auto" -} - -# json prettyfier json() { - if [ -t 0 ]; then # argument + if [ -t 0 ]; then # argument python -m json.tool <<< "$*" - else # pipe + else # pipe python -m json.tool fi } @@ -234,20 +176,18 @@ _get_full_file_extension() { } rmt() { - local filename TRASH + local TRASH TRASH=~/.trash - if [ ! -d "$TRASH" ]; then - mkdir "$TRASH" - fi - + local filename for filename in $* do - mv "$filename" "$TRASH"/"$(basename "$filename")-$(date +%s)" + local filename_out_path="${TRASH}$(realpath "$filename")" + mkdir -p "$(dirname "$filename_out_path")" + mv "$filename" "${filename_out_path}_$(date +%s)" done } -# shows text from ~/.tips/* showtips() { TIPS_DIR="$HOME/.tips" @@ -261,12 +201,10 @@ showtips() { return 0 } - most-often-commands() { history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn } - # calculator = () { echo "$*" | bc -l diff --git a/home/user/.config/zsh/aliases b/home/user/.config/zsh/aliases index fa7044d..8a7dea7 100644 --- a/home/user/.config/zsh/aliases +++ b/home/user/.config/zsh/aliases @@ -1,8 +1,7 @@ alias -g L='| bash -c "$PAGER"' alias -g HL='| highlight -O ansi -S ' -alias -g ALL="1>/dev/null 2>&1" -alias -g BG="&>/dev/null &" -alias -g MOD='$(git diff --name-only --relative --diff-filter="acdr" | tr "\n" " ")' +alias -g ALL="&>/dev/null" +alias -g BG="ALL &" alias -g ?='| grep' alias -g BEEP='&& beep -f 800 -l 250 -n -f 1000 -l 500 || beep -f 800 -l 250 -n -f 500 -l 500'