# do not bell on tab-completion
#set bell-style none
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
# Color files by types
# Note that this may cause completion text blink in some terminals (e.g. xterm).
set colored-stats On
# Append char to indicate type
# set visible-stats On
# Mark symlinked directories
set mark-symlinked-directories On
# Color the common prefix
set colored-completion-prefix On
# Color the common prefix in menu-complete
set menu-complete-display-prefix On
# Enable mode indicator
$if mode=vi
set show-mode-in-prompt on
# Indicate mode with the cursor shape
$if term=linux
set vi-ins-mode-string \1\e[?0c\2
set vi-cmd-mode-string \1\e[?8c\2
$else
set vi-ins-mode-string \1\e[6 q\2
set vi-cmd-mode-string \1\e[2 q\2
$endif
$endif
$if mode=emacs
# for linux console and RH/Debian xterm
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[7~": beginning-of-line
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
"\e[1;5C": forward-word
"\e[1;5D": backward-word
# for rxvt
"\e[8~": end-of-line
# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
"\eOH": beginning-of-line
"\eOF": end-of-line
# for freebsd console
"\e[H": beginning-of-line
"\e[F": end-of-line
$endif
#!/bin/bash
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
iatest=$(expr index "$-" i)
# VIM mode - comment this out if you are not comfirtable with vim or kniw what vim is
set -o vi
# Disable the bell
if [[ $iatest > 0 ]]; then bind "set bell-style visible"; fi
shopt -s globstar # ** to mean reclusive
shopt -s autocd # auto cd when entering just the path
shopt -s checkwinsize # Check the window size after each command and, if necessary, update the values of LINES and COLUMNS
# Allow ctrl-S for history navigation (with ctrl-R)
stty -ixon
# Causes bash to append to history instead of overwriting it so if you start a new terminal, you have old session history
shopt -s histappend
PROMPT_COMMAND='history -a'
# Expand the history size
export HISTFILESIZE=10000
export HISTSIZE=10000
# Don't put duplicate lines in the history and do not add lines that start with a space
export HISTCONTROL=erasedups:ignoreboth
# Make local bin files usable
export PATH=$PATH:$HOME/.local/bin
export PATH=$PATH:$HOME/.local/bin/dm-scripts
export PATH=$PATH:$XDG_CONFIG_HOME/emacs/bin
### SET MANPAGER
export MANPAGER="vim -c ASMANPAGER -"
# Enable history completion with up and down arrow keys
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
# Ignore case on auto-completion
# Note: bind used instead of sticking these in .inputrc
if [[ $iatest > 0 ]]; then bind "set completion-ignore-case on"; fi
# Show auto-completion list automatically, without double tab
# if [[ $iatest > 0 ]]; then bind "set show-all-if-ambiguous On"; fi
# extra completions
[[ $commands[beet] ]] && eval $(beet completion)
function source_config() {
[ -f $1 ] && source $1
}
# Primary imports
source_config $XDG_CONFIG_HOME/shell/exportrc
source_config $XDG_CONFIG_HOME/shell/aliasrc
source_config $XDG_CONFIG_HOME/shell/wol
source_config $XDG_CONFIG_HOME/bash/prompt
source_config $XDG_CONFIG_HOME/bash/localrc
# FZF configs
source_config /usr/share/fzf/key-bindings.bash
source_config /usr/share/fzf/completion.bash
# MPC configs
source_config $XDG_CONFIG_HOME/mpc/mpcvars
function has_command() {
hash "$1" 2>/dev/null
return $?
}
# Source the Starship Prompt
if has_command starship; then eval "$(starship init bash)"; fi
# Script to run on terminal launch
if has_command fastfetch; then fastfetch; fi
# VIM mode - comment this out if you are not comfirtable with vim or kniw what vim is
bindkey -v
unsetopt beep # Disable the bell
setopt autocd # auto cd when entering just the path
Dumb Shell
if [[ "$TERM" == "dumb" ]]
then
unsetopt zle
unsetopt prompt_cr
unsetopt prompt_subst
unfunction precmd
unfunction preexec
PS1='$ '
fi
# History
export SAVEHIST=10000
export HISTSIZE=10000
# Causes zsh to append to history instead of overwriting it so if you start a new terminal, you have old session history
setopt INC_APPEND_HISTORY
# Don't put duplicate lines in the history and do not add lines that start with a space
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
# Make local bin files usable
path+=($HOME/.local/bin)
path+=($HOME/.local/bin/dm-scripts)
path+=($XDG_CONFIG_HOME/emacs/bin)
### SET MANPAGER
export MANPAGER="vim -c ASMANPAGER -"
fpath=($XDG_CONFIG_HOME/zsh/completion $fpath)
zstyle :compinstall filename "$HOME/.zshrc"
# Autocompletion
autoload bashcompinit && bashcompinit # for aws cli
autoload -Uz compinit && compinit # Load autocompletion
zstyle ':completion::complete:*' gain-privileges 1 # Enable aliases for Sudo commands
zstyle ':completion:*' menu select
zstyle ':completion:*' rehash true # automatically rehash bin files
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)(?)*==02=01}:${(s.:.)LS_COLORS}")' # Color the common prefix
# enable history search
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
# extra completions
[[ $commands[kubectl] ]] && source <(kubectl completion zsh)
[[ $commands[beet] ]] && eval $(beet completion)
# create a zkbd compatible hash;
# to add other keys to this hash, see: man 5 terminfo
typeset -g -A key
key[Home]="${terminfo[khome]}"
key[End]="${terminfo[kend]}"
key[Insert]="${terminfo[kich1]}"
key[Backspace]="${terminfo[kbs]}"
key[Delete]="${terminfo[kdch1]}"
key[Up]="${terminfo[kcuu1]}"
key[Down]="${terminfo[kcud1]}"
key[Left]="${terminfo[kcub1]}"
key[Right]="${terminfo[kcuf1]}"
key[PageUp]="${terminfo[kpp]}"
key[PageDown]="${terminfo[knp]}"
key[Shift-Tab]="${terminfo[kcbt]}"
key[Control-Left]="${terminfo[kLFT5]}"
key[Control-Right]="${terminfo[kRIT5]}"
# setup key accordingly
[[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line
[[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line
[[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char
[[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char
[[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-beginning-search
[[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-beginning-search
[[ -n "${key[Left]}" ]] && bindkey -- "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey -- "${key[Right]}" forward-char
[[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history
[[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history
[[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}" reverse-menu-complete
[[ -n "${key[Control-Left]}" ]] && bindkey -- "${key[Control-Left]}" backward-word
[[ -n "${key[Control-Right]}" ]] && bindkey -- "${key[Control-Right]}" forward-word
# Bind ctrl + space to accept the current suggestion.
bindkey '^ ' end-of-line
# Bind Alt + . to insert last argument
bindkey '^[.' insert-last-word
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
autoload -Uz add-zle-hook-widget
function zle_application_mode_start { echoti smkx }
function zle_application_mode_stop { echoti rmkx }
add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
fi
function source_config() {
[ -f $1 ] && source $1
}
# Primary imports
source_config $XDG_CONFIG_HOME/shell/exportrc
source_config $XDG_CONFIG_HOME/shell/aliasrc
source_config $XDG_CONFIG_HOME/shell/wol
source_config $XDG_CONFIG_HOME/zsh/localrc
# FZF configs
source_config /usr/share/fzf/key-bindings.zsh
source_config /usr/share/fzf/completion.zsh
# MPC configs
source_config $XDG_CONFIG_HOME/mpc/mpcvars
# Plugins - need to be loaded at the very end
source_config /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source_config /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
function has_command() {
hash "$1" 2>/dev/null
return $?
}
# Source the Starship Prompt
if has_command starship; then eval "$(starship init zsh)"; fi
# Script to run on terminal launch
if has_command fastfetch; then fastfetch; fi
starship init fish | source
export XDG_DESKTOP_DIR="$HOME/desktop"
export XDG_DOWNLOAD_DIR="$HOME/downloads"
export XDG_TEMPLATES_DIR="$HOME/templates"
export XDG_PUBLICSHARE_DIR="$HOME/public"
export XDG_DOCUMENTS_DIR="$HOME/documents"
export XDG_MUSIC_DIR="$HOME/music"
export XDG_PICTURES_DIR="$HOME/pictures"
export XDG_VIDEOS_DIR="$HOME/videos"
export QT_IM_MODULE=fcitx
export GTK_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export GIT_DIRECTORY="$HOME/projects"
export WALL_DIRECTORY="$XDG_PICTURES_DIR/wallpapers"
export EDITOR=vim
export VISUAL=vim
export HISTFILE="$XDG_STATE_HOME/shell/history"
export LESSHISTFILE="$XDG_CACHE_HOME/less/history"
Environment variables need to be available outside of the shell and so must be defined with a broader scope. Create the following files manually.
/etc/profile.d/xdg.sh
[ -f $HOME/.profile ] && . $HOME/.profile # XDG Directories export XDG_CACHE_HOME=$HOME/.cache export XDG_CONFIG_HOME=$HOME/.config export XDG_DATA_HOME=$HOME/.local/share export XDG_STATE_HOME=$HOME/.local/state # Cache export CCACHE_DIR=$XDG_CACHE_HOME/ccache export CUDA_CACHE_PATH=$XDG_CACHE_HOME/nv export MYPY_CACHE_DIR=$XDG_CACHE_HOME/mypy export PYLINTHOME=$XDG_CACHE_HOME/pylint # Config export DOCKER_CONFIG=$XDG_CONFIG_HOME/docker export GTK2_RC_FILES=$XDG_CONFIG_HOME/gtk-2.0/gtkrc export INPUTRC=$XDG_CONFIG_HOME/readline/inputrc export KDEHOME=$XDG_CONFIG_HOME/kde export MEDNAFEN_HOME=$XDG_CONFIG_HOME/mednafen export PYTHONSTARTUP=$XDG_CONFIG_HOME/python/pythonrc # Data export ANDROID_HOME=$XDG_DATA_HOME/android export CARGO_HOME=$XDG_DATA_HOME/cargo export GNUPGHOME=$XDG_DATA_HOME/gnupg export KODI_DATA=$XDG_DATA_HOME/kodi export MAILDIR=$XDG_DATA_HOME/mail export PASSWORD_STORE_DIR=$XDG_DATA_HOME/passTo temporarily bypass an alias, we precede the command with a `` e.g. the ls command is aliased, but to use the normal ls command you would type `\ls`
#!/usr/bin/env bash
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
if hash doas 2>/dev/null; then
# Use doas instead of sudo
alias sudo='doas'
else
# Enable aliases for Sudo commands
alias sudo='sudo '
fi
alias makepkg='makepkg -si'
alias nano='nano -c'
alias snano='sudo nano'
alias svim='sudo vim'
alias vfm='vifmrun'
if hash eza 2>/dev/null; then
alias eza='eza --icons --group-directories-first'
alias ls='eza' # add file type extensions
alias la='ls -ah' # show hidden files
alias ll='ls -alg' # long listing format
alias tree='eza --tree' # tree listing
alias treed='tree --only-dirs' # tree listing directories
else
alias ls='ls -Fh --color=always' # add colors and file type extensions
alias la='ls -Ah' # show hidden files
alias ll='ls -als' # long listing format
alias tree='tree -CAhF --dirsfirst' # tree listing
alias treed='tree -CAFd' # tree listing directories
fi
alias llf="\ls -l | egrep -v '^d'" # long list files only
alias lld="\ls -l | egrep '^d'" # long list directories only
alias ~='cd ~'
alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
# cd back into the previous directory
alias bd='cd "$OLDPWD"'
# Make directories recursively
alias mkdir='mkdir -p'
# Create and go to the directory
function mkdirg() {
mkdir -p $1
cd $1
}
Copy file with a progress bar
alias cpr="rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1"
alias mvr="rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1 --remove-source-files"
alias scpr="sudo rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1 --rsync-path='sudo rsync'"
alias smvr="sudo rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1 --rsync-path='sudo rsync' --remove-source-files"
function cpp() {
set -e
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 |
awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%3d%% [", percent
for (i=0;i<=percent;i++)
printf "="
printf ">"
for (i=percent;i<100;i++)
printf " "
printf "]\r"
}
}
END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}
# Less
alias less='less -iRJ --use-color'
# Grep
alias grep='grep --colour=auto'
alias sgrep='grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS} '
# Search command line history
alias h="history | grep "
# Search files in the current folder
alias f="find . | grep "
alias ff='find . -type f -name'
alias fd='find . -type d -name'
# Count all files (recursively) in the current folder
alias countfiles="for t in files links directories; do echo \`find . -type \${t:0:1} | wc -l\` \$t; done 2> /dev/null"
# Searches for text in all files in the current folder
function ftext() {
# -i case-insensitive
# -I ignore binary files
# -H causes filename to be printed
# -r recursive search
# -n causes line number to be printed
# optional: -F treat search term as a literal, not a regular expression
# optional: -l only print filenames and not the matching lines ex. grep -irl "$1" *
grep -iIHrn --color=always "$1" . | less -r
}
# Start ArchiSteamFarm
if [[ -d "$HOME/.local/bin/asf" ]]; then
alias asf="$HOME/.local/bin/asf/ArchiSteamFarm"
fi
# Update Proton
alias update-proton="$GIT_DIRECTORY/../SystemSoftware/ProtonUpdater/cproton.sh"
# Setup extra password store
alias pay="PASSWORD_STORE_DIR=$XDG_DATA_HOME/pass-pay pass"
alias bi="beet import"
alias bsi="beet -s import"
alias pman='sudo pacman'
# alias pman-mirrors-update='sudo pacman-mirrors --geoip'
alias pman-orphans-clean='sudo pacman -Rs $(pacman -Qtdq)'
alias pman-orphans-fullclean='sudo pacman -Rns $(pacman -Qtdq)'
# fzf
alias pman-browse="pacman -Slq | fzf --multi --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S"
alias pman-list="pacman -Qq | fzf --multi --preview 'pacman -Qi {1}' | xargs -ro sudo pacman -Rcs"
Update mirrors
function pman-update-mirrors() {
country="$1" # US
curl -s "https://archlinux.org/mirrorlist/?country=$country&protocol=https&use_mirror_status=on" |
sed -e 's/#Server/Server/' -e '/^## \w*$/d' |
rankmirrors - > /tmp/mirrorlist
sudo cp /tmp/mirrorlist /etc/pacman.d/mirrorlist
}
alias reboot='sudo shutdown -r now'
alias forcereboot='sudo shutdown -r -n now'
alias shutdown='sudo shutdown -P'
alias suspend='systemctl suspend'
# Alias's to show disk space and space used in a folder
alias diskspace="du -S | sort -n -r |more"
alias folders='du -h --max-depth=1'
alias folderssort='find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn'
alias mountedinfo='df -hT'
# Audio Outout info
alias aoutput='cat /proc/asound/card2/pcm0p/sub0/hw_params'
# Search running processes
alias p="ps aux | grep "
alias topcpu="/bin/ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10"
# Show all logs in /var/log
alias logs="sudo find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f"
# Show used DNS addresses
alias dnsview='cat /etc/resolv.conf'
# Show current network connections to the server
alias ipview="netstat -anpl | grep :80 | awk {'print \$5'} | cut -d\":\" -f1 | sort | uniq -c | sort -n | sed -e 's/^ *//' -e 's/ *\$//'"
# Show open ports
alias openports='netstat -nape --inet'
# Extend screen
alias extendtolaptop='ssh -YC amadeus x2x -east -to :0.0'
# occ for nextcloud container
alias occ='ssh amadeus "docker exec -i --user www-data nextcloud-app php occ"'
# transmission
alias t='transmission-remote amadeus:9091 --authenv'
# docker
alias dstat='docker stats'
alias dls='docker container ls --format "table {{.ID}}\t{{.RunningFor}}\t{{.Status}}\t{{.Names}}\t{{.Networks}}"'
alias dll='docker container ls --all --format "table {{.ID}}\t{{.Image}}\t{{.RunningFor}}\t{{.State}}\t{{.Status}}\t{{.Names}}\t{{.Networks}}"'
alias dup='docker-compose up -d'
alias dupo='docker-compose up -d --remove-orphans'
alias ddown='docker-compose down'
alias dstop='docker-compose stop'
alias dlog='docker logs'
alias dx='docker exec -it'
alias gs="git fetch && git status"
alias gc="git commit"
alias gp="git push"
alias gf="git fetch --prune"
alias gF="git pull"
alias gd="git diff"
alias glog="git log --oneline"
alias glogl="git log --show-signature"
bare_git_dir="$GIT_DIRECTORY/private-Dotfiles/"
bare_work_tree="$HOME"
alias gprivate="git --git-dir=$bare_git_dir --work-tree=$bare_work_tree"
alias gsprivate="gprivate fetch && gprivate status"
alias gcprivate="gprivate commit"
alias gpprivate="gprivate push"
alias gfprivate="gprivate pull"
alias gdprivate="gprivate diff"
alias pgs="pass git status"
alias pgp="pass git push"
alias pgf="pass git pull"
alias pgl="pass git log --oneline"
Search and play YouTube audio
alias shazam='songrec recognize'
alias ytdv='yt-dlp'
alias ytda='yt-dlp --config-locations ~/.config/yt-dlp/audio.conf'
function yta() {
mpv --ytdl-format=bestaudio ytdl://ytsearch:"$*"
}
function ytv() {
mpv ytdl://ytsearch:"$*"
}
Extracts any archive(s) (if unp isn’t installed)
function ex() {
for archive in $*; do
if [ -f $archive ]; then
case $archive in
*.tar.bz2) tar xvjf $archive ;;
*.tar.gz) tar xvzf $archive ;;
*.bz2) bunzip2 $archive ;;
*.rar) rar x $archive ;;
*.gz) gunzip $archive ;;
*.tar) tar xvf $archive ;;
*.tbz2) tar xvjf $archive ;;
*.tgz) tar xvzf $archive ;;
*.zip) unzip $archive ;;
*.Z) uncompress $archive ;;
*.7z) 7z x $archive ;;
*) echo "don't know how to extract '$archive'..." ;;
esac
else echo "'$archive' is not a valid file!"
fi
done
}
alias ledger="ledger --init-file $XDG_CONFIG_HOME/ledger/ledgerrc"
alias mbsync="mbsync -c $XDG_CONFIG_HOME/isync/mbsyncrc"
# Inserts a blank line between shell prompts
add_newline = true
# Timeout for commands executed by starship (in milliseconds).
# command_timeout = 2000
The character module shows a character (usually an arrow) beside where the text is entered in your terminal.
[character]
# Replace the ❯ symbol in the prompt with ➜
success_symbol = "[➜](bold green)"
error_symbol = "[➜](bold red)"
The hostname module shows the system hostname.
[hostname]
ssh_only = true
The username module shows active user’s username. The module will be shown if any of the following conditions are met:
[username]
show_always = false
The line_break module separates the prompt into two lines.
[line_break]
# Disables the line_break module, making the prompt a single line.
disabled = false
The directory module shows the path to your current directory, truncated to three parent folders. Your directory will also be truncated to the root of the git repo that you’re currently in.
When using the fish style pwd option, instead of hiding the path that is truncated, you will see a shortened name of each directory based on the number you enable for the option.
For example, given ~/Dev/Nix/nixpkgs/pkgs where nixpkgs is the repo root, and the option set to 1. You will now see ~/D/N/nixpkgs/pkgs, whereas before it would have been nixpkgs/pkgs.
[directory]
truncation_length = 3
truncate_to_repo = true
read_only = " "
[aws]
symbol = " "
[buf]
symbol = " "
[c]
symbol = " "
[conda]
symbol = " "
[dart]
symbol = " "
[docker_context]
symbol = " "
[elixir]
symbol = " "
[elm]
symbol = " "
[git_branch]
symbol = " "
[golang]
symbol = " "
[haskell]
symbol = " "
[hg_branch]
symbol = " "
[java]
symbol = " "
[julia]
symbol = " "
[memory_usage]
symbol = " "
[nim]
symbol = " "
[nix_shell]
symbol = " "
[nodejs]
symbol = " "
[package]
symbol = " "
[python]
symbol = " "
[spack]
symbol = "🅢 "
[rust]
symbol = " "