sync/shell/.zshrc

365 lines
11 KiB
Bash
Raw Normal View History

2016-07-18 16:41:37 -04:00
#zmodload zsh/zprof
2016-07-25 03:53:50 -04:00
echo -ne '[ ]\r'
2017-11-27 11:45:01 -05:00
for CONFIG (~/.zsh/*.zsh) source "$CONFIG"
2016-07-18 16:41:37 -04:00
autoload -U compinit
compinit
2016-07-18 16:44:17 -04:00
setopt always_to_end # When completing from the middle of a word, move the cursor to the end of the word
setopt complete_in_word # Allow completion from within a word/phrase
2015-06-23 10:24:46 -04:00
setopt INTERACTIVECOMMENTS
2016-03-19 23:02:25 -04:00
setopt EXTENDED_GLOB
2014-08-29 09:46:43 -04:00
setopt HIST_EXPIRE_DUPS_FIRST
2019-01-19 20:10:36 -05:00
setopt APPEND_HISTORY EXTENDED_HISTORY SHARE_HISTORY HISTIGNOREALLDUPS
2016-05-22 13:52:20 -04:00
export HIST_STAMPS="dd.mm.yyyy"
export HISTSIZE=12000
export SAVEHIST=10000000
2017-11-27 11:45:01 -05:00
export HISTFILE="$HOME/.zsh_history"
2019-01-19 20:10:36 -05:00
export EDITOR="vim"
2016-05-22 13:52:20 -04:00
export FZF_COMPLETION_OPTS='--no-mouse -m -1 -x'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.cache/zsh
2017-11-19 23:14:12 -05:00
# Check if a command exists
2018-11-04 12:23:59 -05:00
ex() {
command -v "$1" >/dev/null
return $?
}
2017-11-19 23:14:12 -05:00
if ex firefox; then
export BROWSER="firefox"
elif ex firefox-bin; then
export BROWSER="firefox-bin"
else
export BROWSER="xdg-open"
fi
2016-01-26 13:47:55 -05:00
# For pasting in commands that start with $
$ () {
2018-11-04 12:23:59 -05:00
"$@"
2016-03-30 13:29:12 -04:00
}
2016-05-22 13:52:20 -04:00
# Run gui application as root by copying xauth credentials
2018-11-04 12:23:59 -05:00
asroot() {
2015-08-21 20:38:19 -04:00
# Use temporary file for added security
2018-11-04 12:23:59 -05:00
TEMPFILE="$(tempfile)"
xauth extract "$TEMPFILE" "$DISPLAY"
2019-01-08 10:22:19 -05:00
sudo zsh -c "xauth merge $TEMPFILE;(srm $TEMPFILE||rm $TEMPFILE)&$@;"
2015-08-21 20:38:19 -04:00
}
2016-05-22 02:08:21 -04:00
# De-symlink
2016-01-22 02:47:34 -05:00
dsl() {
while (( $# > 0 )); do
2018-11-04 12:23:59 -05:00
readlink "$1" 2>&1 >/dev/null && mv "$(readlink "$1")" "$1"
2016-01-22 02:47:34 -05:00
shift
done
}
2016-05-22 13:52:20 -04:00
# Remove directory by removing subdirectories up a level
2018-11-04 12:23:59 -05:00
dedir() {
2016-06-26 21:16:19 -04:00
# Try removing the directory if it's empty, fail silently if you can't
2019-01-08 10:22:19 -05:00
rmdir "$1" 2>/dev/null && return
2016-06-26 21:16:19 -04:00
# Make a uuid to avoid name conflicts
# Ex: dediring sage when sage/sage fails because sage/sage is moved to .
# but since sage/ exists, it can't be moved
2017-04-30 13:14:50 -04:00
local name=$(uuidgen)
2016-06-26 21:16:19 -04:00
# Move the directory to the uuid
2019-01-08 10:22:19 -05:00
mv -n "$1" "$name" || return 1
2016-06-26 21:16:19 -04:00
# Move all files, use (N) in case there is no * or .* matches
2019-02-14 17:17:41 -05:00
mv -n "$name"/{.,}*(N) . || return 2
2019-01-08 10:22:19 -05:00
rmdir "$name" || return 3
2016-01-10 16:41:13 -05:00
}
2017-04-30 13:14:50 -04:00
# Run multitail on logs
2018-11-04 12:23:59 -05:00
mt() {
if [[ -z "$1" ]]; then
2017-02-05 23:29:05 -05:00
echo "Opts:\nm xe gitea dm syncthing g" >&2
return 1
fi
case $1 in
m) sudo multitail /var/log/messages;;
xe) multitail ~/.xsession-errors;;
2016-11-13 02:17:55 -05:00
ef) sudo multitail /var/log/emerge-fetch.log;;
2017-02-05 23:29:05 -05:00
gitea) sudo multitail /var/log/gitea.{err,log};;
dm) dmesg -w;;
syncthing) sudo multitail /var/log/syncthing.{err,log};;
2016-09-20 12:24:40 -04:00
g) sudo watch -c genlop -tc;;
sync) watch grep -e Dirty: -e Writeback: /proc/meminfo;;
2018-11-04 12:23:59 -05:00
*) multitail "$@"
esac
2016-08-12 19:15:11 -04:00
}
2018-11-04 12:23:59 -05:00
run() {
2016-08-18 15:16:56 -04:00
test -f "${1:r}" && rm "${1:r}"
echo "Building..." >&2
2016-10-12 23:42:02 -04:00
gcc -Wall -g -std=c99 "${1:r}.c" -o "${1:r}" && (echo "Running..." >&2;./"${1:r}")
}
2019-01-19 20:10:36 -05:00
ex todotxt && alias t='todotxt'
ex todo-txt && alias t='todo-txt'
alias ta='t a'
2018-11-04 12:23:59 -05:00
ex vim && alias vi='vim'
ex rc-service && alias service='rc-service'
ex ip && alias ip='ip -c'
ex adb && alias apush="adb push -p"
ex adb && alias apull="adb pull -p"
ex mtr && alias mtr='mtr -t'
ex telegram-cli && alias tg='telegram-cli -NWA --disable-link-preview'
ex eix && alias eix="eix -F"
ex tmux && alias tmux='tmux -2'
ex tree && alias tree='tree -C'
ex ocp && alias ocp="ocp -vs0 -dcurses"
2019-03-30 23:19:58 -04:00
alias jupyter='docker run --rm --user="$(id -u):$(id -g)" -v "$PWD":/home/jovyan/work -p 8888:8888 ymatsunaga/octave jupyter notebook --ip 0.0.0.0'
2016-11-13 02:17:55 -05:00
alias con='git x php bin/console'
alias disphost='export DISPLAY=:0.0'
2015-01-16 11:11:49 -05:00
alias l='ls -CF'
2018-11-04 12:23:59 -05:00
alias la='ls -A'
2015-01-20 07:43:44 -05:00
alias less='less -R'
2018-11-04 12:23:59 -05:00
alias ll='ls -AlhF'
2019-01-19 20:10:36 -05:00
alias logout='pkill -u "$USER"'
2018-11-04 12:23:59 -05:00
alias mouse1="xmodmap <(echo pointer = 1 2 3)"
alias mouse2="xmodmap <(echo pointer = 3 2 1)"
alias nmrestart='nmcli radio wifi off;sleep 1;nmcli radio wifi on'
alias resource='. ~/.zshrc'
2018-11-04 12:23:59 -05:00
alias srm='shred -uzv'
if [ "$(uname)" != "Darwin" ]; then
2015-07-30 03:24:10 -04:00
# Not Mac
2019-01-08 10:22:19 -05:00
export PATH="$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$HOME/.cargo/bin:$HOME/go/bin"
alias ls='ls --color=always -F'
2016-05-22 13:52:20 -04:00
alias where="readlink -m"
2016-05-18 02:56:59 -04:00
else
2016-05-22 13:52:20 -04:00
# It is a mac
# Prepend macports directories in /opt/local
if ex greadlink; then
alias readlink='greadlink'
alias where="greadlink -m"
fi
2017-01-30 00:43:41 -05:00
export PATH="/opt/local/sbin:/opt/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$HOME/bin"
2015-07-30 03:24:10 -04:00
fi
2015-07-31 16:52:21 -04:00
if test -f /etc/gentoo-release; then
# Gentoo
2016-07-21 08:27:31 -04:00
alias etup='sudo etc-update'
2018-11-04 12:23:59 -05:00
ins() {
2016-07-21 08:27:31 -04:00
# Sudo echo so we have immediate results on weather sudo worked
sudo echo "Args: $*"
2016-03-13 22:05:07 -04:00
# Beep, verbose, ask
2016-11-13 02:17:55 -05:00
sudo emerge --autounmask-write -Ava $*
2018-11-26 13:19:49 -05:00
tput bel
2016-03-13 22:05:07 -04:00
}
2018-11-26 13:19:49 -05:00
if ex eix-sync; then
alias update="sudo eix-sync; tput bel"
elif eix emaint; then
alias update="sudo emaint sync -A; tput bel"
fi
2018-11-04 12:23:59 -05:00
upgrade() {
2016-07-21 08:27:31 -04:00
# Sudo echo so we have immediate results on weather sudo worked
sudo echo "Args: $*"
2017-01-12 14:56:55 -05:00
sudo emerge --update --newuse --deep --verbose --tree --keep-going=y --verbose-conflicts --alert --ask --binpkg-respect-use=y --binpkg-changed-deps=y --backtrack=30 $* @world
2018-11-26 13:19:49 -05:00
tput bel
2016-07-21 08:27:31 -04:00
}
2015-07-31 16:52:21 -04:00
elif test -f /etc/lsb-release; then
# Ubuntu
2018-01-14 23:58:31 -05:00
alias install='sudo apt install'
alias remove='sudo apt remove'
alias update='sudo apt update'
alias upgrade='sudo apt upgrade'
alias autoremove='sudo apt autoremove'
alias updateall='sudo sh -c "apt update;apt full-upgrade -y"'
2016-05-22 13:52:20 -04:00
alias search='apt-cache search'
fi
alias ..='k ..'
alias ...='k ../..'
alias ....='k ../../..'
alias .....='k ../../../..'
alias ......='k ../../../../..'
alias .......='k ../../../../../..'
alias ........='k ../../../../../../..'
alias .........='k ../../../../../../../..'
alias ..........='k ../../../../../../../../..'
alias ...........='k ../../../../../../../../../..'
alias ............='k ../../../../../../../../../../..'
alias .............='k ../../../../../../../../../../../..'
alias ..............='k ../../../../../../../../../../../../..'
alias ...............='k ../../../../../../../../../../../../../..'
2018-11-04 12:23:59 -05:00
ex youtube-dl && alias ytdl="youtube-dl -x --audio-format mp3 --audio-quality 0 -c -o '%(title)s.%(ext)s'"
if ex wemux; then
alias tux="wemux"
elif ex tmux; then
alias tux="tmux a || tmux"
fi
if ex git; then
alias g="git"
fi
2018-07-02 22:22:26 -04:00
alias stdns="sudo sh -c 'echo nameserver 1.1.1.1 > /etc/resolv.conf'"
2014-09-28 11:45:17 -04:00
alias fk='k `fzf --no-mouse -m -1 -x`'
2017-02-01 20:16:32 -05:00
alias susp="sudo true && (slock&until echo mem|sudo tee /sys/power/state>/dev/null;do sleep 1;done;sleep 4;nmcli radio wifi off;sleep 3;nmcli radio wifi on)"
if ex sudo; then
alias s='sudo -Hu'
fi
2016-09-27 13:48:54 -04:00
alias -g PA='2>&1 | paste'
if ex rsync; then
2017-10-10 17:24:36 -04:00
alias -g c='rsync --no-inc-recursive --partial -ha --info=progress2 "$@"'
alias -g cfat='rsync --no-inc-recursive --partial -hrlc --info=progress2 "$@"'
alias cp='rsync --no-inc-recursive --partial -ha --info=progress2 "$@"'
fi
2016-05-22 13:52:20 -04:00
alias -g nify=" > /dev/null 2>&1 &"
alias -g nifyd=" > /dev/null 2>&1 & disown"
2018-11-26 13:19:49 -05:00
alias -g L="|& less"
2018-07-02 16:01:13 -04:00
if ex mktemp; then
alias mtmp='pushd "$(mktemp -d)" >/dev/null'
fi
2017-02-14 01:43:24 -05:00
if ex rg; then
alias -g G='|& rg'
2017-04-30 13:14:50 -04:00
alias rg='rg -i'
2018-11-04 12:23:59 -05:00
# I'm so sorry, ggreer
2017-02-14 01:43:24 -05:00
alias ag=rg
elif ex ag; then
alias -g G='|& ag'
elif ex egrep; then
alias -g G='|& egrep'
elif ex grep; then
alias -g G='|& grep'
fi
2018-11-26 13:19:49 -05:00
alias bp="tput bel"
2016-09-09 12:01:04 -04:00
timer() {
for i in {1.."$1"}; do
sleep 1
echo
done | pv -Sptels "$1" >/dev/null
}
2018-11-04 12:23:59 -05:00
fixsh() {
sed -i'' -e "${1}d" ~/.ssh/known_hosts
2016-05-22 13:52:20 -04:00
}
mv() { /bin/mv -v "$@" }
m() { mv "$@" }
2017-05-08 22:24:12 -04:00
compdef _cp c cfat m mv cp adb apush apull
2017-11-19 23:14:12 -05:00
linx() {
if [[ -z "$1" ]]; then
2018-01-14 23:58:31 -05:00
curl -T- -H "Linx-Randomize: yes" -H "Linx-Expiry: 2592000" https://linx.austenwares.com/upload | perl -pe 's/https:\/\/linx.austenwares.com\/(\w+)/https:\/\/linx.austenwares.com\/selif\/\1/'
2017-11-19 23:14:12 -05:00
elif (( $# == 1 )) && [[ -f "$1" ]]; then
linx < "$1"
else
2018-11-04 12:23:59 -05:00
tar -cf - "$@" | linx
2017-11-19 23:14:12 -05:00
fi
}
2018-11-04 12:23:59 -05:00
ltar() {
tar -cf - "$@"|pv -WcN tar|xz|pv -WcN lzma
2015-02-23 13:12:42 -05:00
}
2018-11-04 12:23:59 -05:00
ctar() {
tar -cf - "$@"|pv -WcN tar|gzip|pv -WcN gzip
2016-03-28 12:36:55 -04:00
}
2018-11-04 12:23:59 -05:00
offline() {
2016-01-21 12:20:18 -05:00
if [ ! -z "$@" ] ; then
2018-11-04 12:23:59 -05:00
sudo unshare -n -- sudo -u "$USER" zsh -c "$@"
2016-01-21 12:20:18 -05:00
else
2018-11-04 12:23:59 -05:00
sudo unshare -n -- sudo -u "$USER" LP_MARK_PREFIX=" $(tput setaf 1)(offline)$(tput sgr0) " zsh
2016-01-21 12:20:18 -05:00
fi
}
2018-11-04 12:23:59 -05:00
tsh() {
ssh "$@"
echo "\n\n\n\n\n\n\n\n\n\nSESSION CLOSED\n\n\n\n\n\n\n\n\n\n"
}
2016-07-21 08:27:31 -04:00
compdefas () {
local a
a="$1"
shift
compdef "$_comps[$a]" "${(@)*}=$a"
}
compdefas ssh tsh
compdefas mv m mv
2018-11-04 12:23:59 -05:00
mcl() {
2019-01-19 20:10:36 -05:00
mkdir -p "$1"
cd "$1"
}
2018-11-04 12:23:59 -05:00
rc() {
2015-08-18 18:38:07 -04:00
case $1 in
z) vim ~/.zshrc;;
v) vim ~/.vimrc;;
2019-01-19 20:10:36 -05:00
i) vim ~/.config/i3/config;;
2015-08-23 11:44:31 -04:00
use) sudo vim /etc/portage/package.use/package.use;;
make) sudo vim /etc/portage/make.conf;;
2016-02-08 10:48:11 -05:00
unmask) sudo vim /etc/portage/package.unmask/package.unmask;;
2015-08-23 11:44:31 -04:00
mask) sudo vim /etc/portage/package.mask/package.mask;;
accept_keywords) sudo vim /etc/portage/package.accept_keywords/package.accept_keywords;;
2016-08-21 01:50:17 -04:00
keywords) sudo vim /etc/portage/package.keywords/package.keywords;;
2016-02-05 00:18:49 -05:00
license) sudo vim /etc/portage/package.license/package.license;;
2016-08-21 01:50:17 -04:00
*) echo "Opts:\nz v i\nuse make unmask mask accept_keywords keywords license"
2015-08-23 11:44:31 -04:00
esac
}
2018-11-04 12:23:59 -05:00
k() {
2019-01-19 20:10:36 -05:00
# More than 1 arguement
if [[ $# > 1 ]] ; then
2015-06-10 17:01:47 -04:00
vim $@
elif [ -d "$@" ] ; then
cd "$@" && ls
2014-08-11 15:14:46 -04:00
elif [[ "$@" == "-" ]] ; then
2019-01-19 20:10:36 -05:00
# Because if this isn't here, k - won't work
cd - && ls
elif [ -f "$@" ] ; then
2019-01-19 20:10:36 -05:00
# Extract if it's extractable
case $1 in
2017-04-30 13:14:50 -04:00
# Images
*.png|*.jpg|*.gif) feh "$1" ;;
# Documents
*.pdf|*.ps) okular "$1" ;;
*.odt|*.doc|*.docx) libreoffice "$1" ;;
*.odp|*.ppt|*.pptx) libreoffice "$1" ;;
*.ods|*.xls|*.xlsx) libreoffice "$1" ;;
# Compressed files
*.tar.xz) pv "$1"|tar -xJf - ;;
*.txz) pv "$1"|tar -xJf - ;;
*.tar.bz2) pv "$1"|tar -xjf - ;;
*.tar.gz) pv "$1"|tar -xzf - ;;
*.tar) pv "$1"|tar -xf - ;;
*.tbz) pv "$1"|tar -xjf - ;;
*.tbz2) pv "$1"|tar -xjf - ;;
*.tgz) pv "$1"|tar -xzf - ;;
*.lzma) pv "$1"|tar --lzma -xf - ;;
*.xz) pv "$1"|tar -xJf - ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*.lrz) lrzuntar "$1" ;;
*) vim "$1"
esac
else
2019-01-19 20:10:36 -05:00
# Edit with vim
2015-06-10 17:01:47 -04:00
echo -n "vim? "
read a
2015-06-10 17:01:47 -04:00
vim "$@"
fi
}
if (( $+TMUX )) || [[ "$TERM" = "screen-256color" ]] || [[ "$TERM" = "screen.xterm-256color" ]]; then
unset zle_bracketed_paste
fi
2016-02-05 00:18:49 -05:00
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
if ex fasd; then
2016-07-18 19:54:00 -04:00
eval "$(fasd --init auto)"
fi
2016-05-22 13:52:20 -04:00
2016-07-25 03:53:50 -04:00
echo -ne '[# ]\r'
2019-01-19 20:10:36 -05:00
#source ~/.zsh-git/liquidprompt/liquidprompt
2018-02-18 12:22:37 -05:00
if [[ -f ~/.zsh-git/custom-config/zshrc ]]; then
source ~/.zsh-git/custom-config/zshrc
2017-11-27 11:45:01 -05:00
fi
2019-04-02 09:45:18 -04:00
2019-01-19 20:10:36 -05:00
function prompt_pre() {
2019-04-02 09:45:18 -04:00
export CESIUM_LAST_COMMAND_TIME="$(date +%s)"
2019-01-19 20:10:36 -05:00
}
function prompt_cmd() {
2019-04-02 09:45:18 -04:00
PS1="$(cesium --mode ps1 --rc "$?" --shell zsh)"
RPS1="$(cesium --mode rps1 --rc "$?" --shell zsh)"
2019-01-19 20:10:36 -05:00
unset CESIUM_LAST_COMMAND_TIME
}
2019-01-22 10:21:58 -05:00
autoload -Uz add-zsh-hook
precmd_functions+=(prompt_cmd)
add-zsh-hook preexec prompt_pre
2019-04-02 09:45:18 -04:00
#function prompt_pre() {
# CESIUM_LAST_COMMAND_TIME="$(date +%s)"
#}
#function prompt_cmd() {
# PS1="$(CESIUM_LAST_COMMAND_TIME="$CESIUM_LAST_COMMAND_TIME" RC="$?" ~/git/cesium/cesium --mode ps1 --shell zsh)"
# RPS1="$(CESIUM_LAST_COMMAND_TIME="$CESIUM_LAST_COMMAND_TIME" RC="$?" ~/git/cesium/cesium --mode rps1 --shell zsh)"
# unset CESIUM_LAST_COMMAND_TIME
#}
#autoload -Uz add-zsh-hook
#precmd_functions+=(prompt_cmd)
#add-zsh-hook preexec prompt_pre
2016-07-25 03:53:50 -04:00
echo -e '[##]'
2016-07-18 16:41:37 -04:00
#zprof