# recommended by VTE source /etc/zsh/zprofile bindkey -e # emacs mode alias ls="ls --classify --color --group-directories-first --quoting-style=literal" which exa > /dev/null if [[ $? -eq 0 ]]; then alias l="exa --group --long --git --group-directories-first --extended --binary" alias ll="l --all" alias lt="l --tree" alias llt="ll --tree" alias lt2="lt --level=2" alias llt2="llt --level=2" alias lt3="lt --level=3" alias llt3="llt --level=3" alias lt4="lt --level=4" alias llt4="llt --level=4" alias lt5="lt --level=5" alias llt5="llt --level=5" else alias l="ls --human-readable -l" alias ll="l --almost-all" fi alias cp="cp --reflink=auto" alias grep="grep --text --color=auto" alias pull_website="wget --no-parent --recursive --page-requisites --convert-links --html-extension --no-clobber" alias ..="cd .." alias htop="htop --delay=3" alias O=xdg-open alias gits="git status" alias gita="git add" alias gitc="git commit" alias gitp="git push" alias gitl="git log --shortstat --graph" alias gitd="git diff --word-diff" which yt-dlp > /dev/null if [[ $? -eq 0 ]]; then alias Y="noglob yt-dlp --no-check-certificate -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]'" alias Ysound="noglob yt-dlp --no-check-certificate -f bestaudio" else alias Y="noglob youtube-dl --no-check-certificate -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]'" alias Ysound="noglob youtube-dl --no-check-certificate -f bestaudio" fi alias battery="upower -i /org/freedesktop/UPower/devices/battery_BAT0" alias pp=python2 alias ppp=python3 alias Ju="journalctl --unit" alias Jue="journalctl --pager-end --unit" alias Juf="journalctl --follow --unit" alias Ss="systemctl status --no-pager" alias SE="systemctl enable" alias SD="systemctl disable" alias SS="systemctl start" alias SR="systemctl restart" alias SL="systemctl reload" alias SX="systemctl stop" alias uJu="journalctl --user --unit" alias uJue="journalctl --user --pager-end --unit" alias uJuf="journalctl --user --follow --unit" alias uSs="systemctl --user status --no-pager" alias uSE="systemctl --user enable" alias uSD="systemctl --user disable" alias uSS="systemctl --user start" alias uSR="systemctl --user restart" alias uSL="systemctl --user reload" alias uSX="systemctl --user stop" alias dmesg="dmesg -e" # apparently this is the only way of setting GNU Screen to UTF-8 alias screen="screen -U" # Edit the current command line in $EDITOR export VISUAL="nano" autoload -U edit-command-line zle -N edit-command-line bindkey '\C-e' edit-command-line notify () { notify-send -u critical "Attention required on $(tty)" "${1}" } mkcd () { mkdir -p "$1" && cd "$1" } mkv-fixtitles () { for arg in "$@" do title="${arg%%.[mM][kK][vV]}" mkvpropedit "$arg" --set "title=$title" --edit track:v1 --delete name > /dev/null if [ $? -ne 0 ]; then echo "$arg failed" fi done } psg () { ps axu | grep -v grep | grep -i $* } # hledání v běžících procesech pskill () { pids=($(psg $1|awk '{print $2}')) for pid in $pids; do echo "Killing $pid..." kill $pid done } psm () { pid=(${=$(psg $1|grep -o --color=no -E "[0-9]+")}) echo "Found pid=${pid[1]}." scanmem -p ${pid[1]} } zres () { . /etc/zsh/zshrc [[ -f ~/.zshrc ]] && . ~/.zshrc hash -r } # kill GNU Screen pages in the specified range kill_screens () { for p in {$1..$2} do screen -p $p -X stuff "exit\n" done } http-dir () { echo "Serving $PWD on 0.0.0.0:55555" python3 -m http.server 55555 } function die () { echo "died during ${1}" exit 1 } function mkvoid () { __MKVOID_TARGET="$1" __MKVOID_PATH="${__MKVOID_TARGET:P}" __MKVOID_DIR="${__MKVOID_PATH:h}" __MKVOID_NAME="${__MKVOID_PATH:t}" __MKVOID_ID="/dev/shm/void/${__MKVOID_PATH:l:gs/\///:gs/ //}" mkdir -p "/dev/shm/void" || die "mkdir void" mkdir "${__MKVOID_ID}" || die "mkdir shm" mkdir -p "${__MKVOID_DIR}" || die "mkdir fs" ln -s "${__MKVOID_ID}" "${__MKVOID_PATH}" || die "ln" pushd "${__MKVOID_PATH}" > /dev/null || die "pushd" OVER_PROMPT_VOIDS="$OVER_PROMPT_VOIDS:$__MKVOID_NAME" zsh popd > /dev/null while true; do fuser -s "${__MKVOID_PATH}" if [[ $? == 1 ]]; then break else echo -n ">>> Waiting for other processes to abandon this void.\r" fi sleep 5 done rm -f "${__MKVOID_PATH}" || die "rm link" rm -rf "${__MKVOID_ID}" || die "rm void" } # loop-shell COMMAND creates a shell that takes user_input and runs COMMAND user_input # e.g. "loop-shell grep -ri" creates a grepping shell function loop-shell { while true do echo -n "-> " read Q $@ $Q done } # history including search HISTFILE=~/.history HISTSIZE=10000000 SAVEHIST=10000000 setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format. setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history. setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again. setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate. setopt HIST_FIND_NO_DUPS # Do not display a line previously found. setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space. setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file. setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry. setopt HIST_VERIFY # Don't execute immediately upon history expansion. bindkey '\e[A' history-beginning-search-backward # completion from history with Up/Down keys bindkey '\e[B' history-beginning-search-forward # # general prompt hooks incl. history management # (only commit successful commands, but cache all) # © http://scarff.id.au/blog/2019/zsh-history-conditional-on-command-success/ function zshaddhistory() { ## called before a history line is saved. See zshmisc(1). # Prevent the command from being written to history before it's # executed; save it to LASTHIST instead. Write it to history # in precmd. LASTHIST=$1 # Return value 2: "... the history line will be saved on the internal # history list, but not written to the history file". return 2 } function precmd() { ## zsh hook called before the prompt is printed. See zshmisc(1). # Write the last command if successful, using the history buffered by # zshaddhistory(). if [[ $? == 0 && -n "$LASTHIST" && -n $HISTFILE ]] ; then print -sr "${LASTHIST%%$'\n'}" fi # over-prompt tie in if [[ ! -v OVER_PROMPT_DISABLED ]]; then __over_prompt_precmd || export OVER_PROMPT_DISABLED=1 fi } function preexec () { if [[ ! -v OVER_PROMPT_DISABLED ]]; then __over_prompt_preexec "$1" || export OVER_PROMPT_DISABLED=1 fi } # general settings setopt EXTENDED_GLOB unsetopt NO_CLOBBER # prevents cat < file > file but gets in the way unsetopt CORRECTALL # hell no setopt NO_BEEP # hell no unsetopt equals # allows me to use strings like =this without escaping # File completion export ZLE_REMOVE_SUFFIX_CHARS=$' \t\n;&' # don't remove these chars after completion setopt AUTOLIST setopt NO_LIST_AMBIGUOUS # list files immediately setopt LIST_PACKED zmodload -i zsh/complist # colors zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} zstyle ':completion::complete:*' use-cache 1 zstyle ':completion:*' special-dirs true autoload -U compinit compinit autoload colors zsh/terminfo # app-shells/over-env source /usr/share/over-env/prompt-init export PYTHONSTARTUP="/usr/share/over-env/python-startup.py" # keyboard stuff bindkey "\e[3~" delete-char # Delete bindkey "\e[1~" beginning-of-line # Home bindkey "\e[H" beginning-of-line # Home bindkey "\e[4~" end-of-line # End bindkey "\e[F" end-of-line # End bindkey "\e[5~" beginning-of-history # PgUp bindkey "\e[6~" end-of-history # PgDn bindkey "\e[1;5D" backward-word # Ctrl ← bindkey "\e[1;5C" forward-word # Ctrl → # load syntax highlighting if available; Gentoo and Arch paths are tried for HPATH in "/usr/share/zsh/site-functions/zsh-syntax-highlighting.zsh" "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" do if [[ -e "${HPATH}" ]]; then source "${HPATH}" break fi done