fix default value in some aliases and functions

This commit is contained in:
TheK4n 2023-11-15 11:50:44 +03:00
parent d89dc71208
commit 160094ce85
3 changed files with 24 additions and 21 deletions

View File

@ -5,9 +5,7 @@ if [ -x "$(command -v dircolors)" ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias grep='grep --color=auto' alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto' alias fgrep='fgrep --color=auto'
alias ls='ls -v --color=auto' alias ls='ls -v --color=auto'
fi fi
@ -16,7 +14,7 @@ alias ll='ls -lhFv'
alias la='ls -AFv' alias la='ls -AFv'
alias lla='ls -lhFAv' alias lla='ls -lhFAv'
alias ll.='ls -lhFAv --ignore="*"' alias ll.='ls -lhFAv --ignore="*"'
alias lsl='_f() { ls -lhFA --color=always "${1:=.}" | tail -n +2 | bash -c "$PAGER" ; }; _f' alias lsl='_f() { ls -lhFA --color=always "${1:-.}" | tail -n +2 | bash -c "$PAGER" ; }; _f'
alias _='sudo' alias _='sudo'
@ -30,7 +28,7 @@ alias ..='cd ..'
alias ...='cd ../..' alias ...='cd ../..'
alias ....='cd ../../..' alias ....='cd ../../..'
alias .3='cd ../../..' alias .3='cd ../../..'
alias cl='_f() { cd "${1:=$HOME}" && ls -F --color=auto ; }; _f' alias cl='_f() { cd "${1:-$HOME}" && ls; }; _f'
alias path='echo -e ${PATH//:/\\n}' alias path='echo -e ${PATH//:/\\n}'

View File

@ -8,7 +8,7 @@ _sod() {
} }
lt() { lt() {
du -h "${1:=.}" 2>/dev/null | sort -h | tac du -h "${1:-.}" 2>/dev/null | sort -h | tac
} }
destroy() { destroy() {
@ -21,7 +21,7 @@ destroy() {
} }
workon() { workon() {
source /opt/pythonenv/"${1:=$(basename $PWD)}"/bin/activate source /opt/pythonenv/"${1:-$(basename $PWD)}"/bin/activate
} }
py() { py() {
@ -33,7 +33,7 @@ py() {
} }
ve() { ve() {
python3 -m virtualenv "${1:=venv}" && . "${1:=venv}/bin/activate" python3 -m virtualenv "${1:-venv}" && . "${1:-venv}/bin/activate"
} }
va() { va() {
@ -132,14 +132,19 @@ vpn() {
) )
} }
# setup ssh tunnel to server $1 as proxy toggle-ssh-proxy() {
toggle-proxy() { if [ -v http_proxy ]; then
if [ -z "$http_proxy" ]; then unset {http,https,ftp,rsync,no}_proxy
export {http,https,ftp,rsync}_proxy="socks5://127.0.0.1:8888" echo "Disabled"
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
ssh -vCTN -D 0.0.0.0:8888 "$1" 1>/dev/null 2>&1 &
else else
unset {http,https,ftp,rsync,no} if [ -z "$1" ]; then
echo "Proxy ssh server hostname not specified" 1>&2
return 1
fi
ssh -vCTN -D 1080 "$1" 1>/dev/null 2>&1 &
export {http,https,ftp,rsync}_proxy="socks5://127.0.0.1:1080" && \
export no_proxy="localhost,127.0.0.1/8,localaddress,.localdomain.com,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12"
echo "Enabled"
fi fi
} }
@ -149,13 +154,14 @@ open() {
} }
split-file() { split-file() {
local _size
test -z "$2" && _size=1G || _size="$2"
test -e "$1" || return 1 test -e "$1" || return 1
local _size="${2:-1G}"
test -d "$1" && \ if [ -d "$1" ]; then
(mkdir "$1.tar.gz.splitted" && cd "$1.tar.gz.splitted" && tar -cz "../$1" | split -d -b "$_size") || \ (mkdir "$1.tar.gz.splitted" && cd "$1.tar.gz.splitted" && tar -cz "../$1" | split -d -b "$_size")
else
(mkdir "$1.splitted" && cd "$1.splitted" && split -d -b "$_size" "../$1") (mkdir "$1.splitted" && cd "$1.splitted" && split -d -b "$_size" "../$1")
fi
} }
json() { json() {
@ -189,7 +195,6 @@ rmt() {
} }
showtips() { showtips() {
TIPS_DIR="$HOME/.tips" TIPS_DIR="$HOME/.tips"
if [ ! -d "$TIPS_DIR" ]; then if [ ! -d "$TIPS_DIR" ]; then
@ -202,7 +207,7 @@ showtips() {
} }
most-often-commands() { most-often-commands() {
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn history 0 | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn
} }
# calculator # calculator

View File

@ -181,7 +181,7 @@ cmd_install() {
for target in "$@" for target in "$@"
do do
if target_exists "$target"; then if target_exists "$target"; then
SANDBOX_PATH="$(mktemp -td "${USER:=user}.dotfiles_XXXXXXX")" SANDBOX_PATH="$(mktemp -td "${USER:-user}.dotfiles_XXXXXXX")"
export SANDBOX_PATH export SANDBOX_PATH
install_target "$target" install_target "$target"
rm -rf "$SANDBOX_PATH" rm -rf "$SANDBOX_PATH"