#zmodload zsh/zprof echo -ne '[ ]\r' for CONFIG (~/.zsh/*.zsh) source "$CONFIG" autoload -U compinit compinit 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 setopt INTERACTIVECOMMENTS setopt EXTENDED_GLOB setopt HIST_EXPIRE_DUPS_FIRST setopt APPEND_HISTORY EXTENDED_HISTORY SHARE_HISTORY HISTIGNOREALLDUPS export HIST_STAMPS="dd.mm.yyyy" export HISTSIZE=12000 export SAVEHIST=10000000 export HISTFILE="$HOME/.zsh_history" export EDITOR="vim" export FZF_COMPLETION_OPTS='--no-mouse -m -1 -x' zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ~/.cache/zsh # Check if a command exists ex() { command -v "$1" >/dev/null return $? } if ex firefox; then export BROWSER="firefox" elif ex firefox-bin; then export BROWSER="firefox-bin" else export BROWSER="xdg-open" fi # For pasting in commands that start with $ $ () { "$@" } # Run gui application as root by copying xauth credentials asroot() { # Use temporary file for added security TEMPFILE="$(tempfile)" xauth extract "$TEMPFILE" "$DISPLAY" sudo zsh -c "xauth merge $TEMPFILE;(srm $TEMPFILE||rm $TEMPFILE)&$@;" } # De-symlink dsl() { while (( $# > 0 )); do readlink "$1" 2>&1 >/dev/null && mv "$(readlink "$1")" "$1" shift done } # Remove directory by removing subdirectories up a level dedir() { # Try removing the directory if it's empty, fail silently if you can't rmdir "$1" 2>/dev/null && return # 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 local name=$(uuidgen) # Move the directory to the uuid mv -n "$1" "$name" || return 1 # Move all files, use (N) in case there is no * or .* matches mv -n "$name"/{.,}* . || return 2 rmdir "$name" || return 3 } # Run multitail on logs mt() { if [[ -z "$1" ]]; then 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;; ef) sudo multitail /var/log/emerge-fetch.log;; gitea) sudo multitail /var/log/gitea.{err,log};; dm) dmesg -w;; syncthing) sudo multitail /var/log/syncthing.{err,log};; g) sudo watch -c genlop -tc;; sync) watch grep -e Dirty: -e Writeback: /proc/meminfo;; *) multitail "$@" esac } run() { test -f "${1:r}" && rm "${1:r}" echo "Building..." >&2 gcc -Wall -g -std=c99 "${1:r}.c" -o "${1:r}" && (echo "Running..." >&2;./"${1:r}") } ex todotxt && alias t='todotxt' ex todo-txt && alias t='todo-txt' alias ta='t a' 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" alias jupyter='docker run --rm --user="$(id -u):$(id -g)" -v "$PWD":/home/jovyan/work -p 8888:8888 ymatsunaga/octave' alias con='git x php bin/console' alias disphost='export DISPLAY=:0.0' alias l='ls -CF' alias la='ls -A' alias less='less -R' alias ll='ls -AlhF' alias logout='pkill -u "$USER"' 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' alias srm='shred -uzv' if [ "$(uname)" != "Darwin" ]; then # Not Mac 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' alias where="readlink -m" else # It is a mac # Prepend macports directories in /opt/local if ex greadlink; then alias readlink='greadlink' alias where="greadlink -m" fi 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" fi if test -f /etc/gentoo-release; then # Gentoo alias etup='sudo etc-update' ins() { # Sudo echo so we have immediate results on weather sudo worked sudo echo "Args: $*" # Beep, verbose, ask sudo emerge --autounmask-write -Ava $* tput bel } 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 upgrade() { # Sudo echo so we have immediate results on weather sudo worked sudo echo "Args: $*" 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 tput bel } elif test -f /etc/lsb-release; then # Ubuntu 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"' 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 ../../../../../../../../../../../../../..' 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 alias stdns="sudo sh -c 'echo nameserver 1.1.1.1 > /etc/resolv.conf'" alias fk='k `fzf --no-mouse -m -1 -x`' 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 alias -g PA='2>&1 | paste' if ex rsync; then 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 alias -g nify=" > /dev/null 2>&1 &" alias -g nifyd=" > /dev/null 2>&1 & disown" alias -g L="|& less" if ex mktemp; then alias mtmp='pushd "$(mktemp -d)" >/dev/null' fi if ex rg; then alias -g G='|& rg' alias rg='rg -i' # I'm so sorry, ggreer 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 alias bp="tput bel" timer() { for i in {1.."$1"}; do sleep 1 echo done | pv -Sptels "$1" >/dev/null } fixsh() { sed -i'' -e "${1}d" ~/.ssh/known_hosts } mv() { /bin/mv -v "$@" } m() { mv "$@" } compdef _cp c cfat m mv cp adb apush apull linx() { if [[ -z "$1" ]]; then 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/' elif (( $# == 1 )) && [[ -f "$1" ]]; then linx < "$1" else tar -cf - "$@" | linx fi } ltar() { tar -cf - "$@"|pv -WcN tar|xz|pv -WcN lzma } ctar() { tar -cf - "$@"|pv -WcN tar|gzip|pv -WcN gzip } offline() { if [ ! -z "$@" ] ; then sudo unshare -n -- sudo -u "$USER" zsh -c "$@" else sudo unshare -n -- sudo -u "$USER" LP_MARK_PREFIX=" $(tput setaf 1)(offline)$(tput sgr0) " zsh fi } tsh() { ssh "$@" echo "\n\n\n\n\n\n\n\n\n\nSESSION CLOSED\n\n\n\n\n\n\n\n\n\n" } compdefas () { local a a="$1" shift compdef "$_comps[$a]" "${(@)*}=$a" } compdefas ssh tsh compdefas mv m mv mcl() { mkdir -p "$1" cd "$1" } rc() { case $1 in z) vim ~/.zshrc;; v) vim ~/.vimrc;; i) vim ~/.config/i3/config;; use) sudo vim /etc/portage/package.use/package.use;; make) sudo vim /etc/portage/make.conf;; unmask) sudo vim /etc/portage/package.unmask/package.unmask;; mask) sudo vim /etc/portage/package.mask/package.mask;; accept_keywords) sudo vim /etc/portage/package.accept_keywords/package.accept_keywords;; keywords) sudo vim /etc/portage/package.keywords/package.keywords;; license) sudo vim /etc/portage/package.license/package.license;; *) echo "Opts:\nz v i\nuse make unmask mask accept_keywords keywords license" esac } k() { # More than 1 arguement if [[ $# > 1 ]] ; then vim $@ elif [ -d "$@" ] ; then cd "$@" && ls elif [[ "$@" == "-" ]] ; then # Because if this isn't here, k - won't work cd - && ls elif [ -f "$@" ] ; then # Extract if it's extractable case $1 in # 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 # Edit with vim echo -n "vim? " read a vim "$@" fi } if (( $+TMUX )) || [[ "$TERM" = "screen-256color" ]] || [[ "$TERM" = "screen.xterm-256color" ]]; then unset zle_bracketed_paste fi [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh if ex fasd; then eval "$(fasd --init auto)" fi echo -ne '[# ]\r' #source ~/.zsh-git/liquidprompt/liquidprompt if [[ -f ~/.zsh-git/custom-config/zshrc ]]; then source ~/.zsh-git/custom-config/zshrc fi function prompt_pre() { export CESIUM_LAST_COMMAND_TIME="$(date +%s)" } function prompt_cmd() { PS1="$(~/git/cesium/cesium --mode ps1 --rc "$?" --shell zsh)" RPS1="$(~/git/cesium/cesium --mode rps1 --rc "$?" --shell zsh)" unset CESIUM_LAST_COMMAND_TIME } function tmp() { autoload -Uz add-zsh-hook precmd_functions+=(prompt_cmd) add-zsh-hook preexec prompt_pre } echo -e '[##]' #zprof