Re-organize the shells' initialization logic
- unify ~/.config/shell/aliases.sh and ~/.config/shell/utils.sh into a common ~/.config/shell/init.sh - split the contents of ~/.config/shell/aliases.sh into the folder ~/.config/shell/aliases.d - split the contents of ~/.config/shell/utils.sh into the folder ~/.config/shell/utils.d
This commit is contained in:
parent
8aad11aed1
commit
a8f8caccc0
17 changed files with 665 additions and 621 deletions
7
.config/shell/aliases.d/README.md
Normal file
7
.config/shell/aliases.d/README.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Shell Aliases
|
||||
|
||||
This folder contains various files that define aliases
|
||||
to be used in the shell.
|
||||
|
||||
Originally, they all were defined in one big "~/.config/shell/aliases.sh" file
|
||||
but are now split across many smaller files here for clarity.
|
||||
59
.config/shell/aliases.d/files.sh
Normal file
59
.config/shell/aliases.d/files.sh
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# Make working with files more convenient
|
||||
|
||||
|
||||
_command_exists() {
|
||||
command -v "$1" 1>/dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
# Avoid bad mistakes and show what happens
|
||||
alias cp="cp --interactive --verbose"
|
||||
alias ln='ln --interactive --verbose'
|
||||
alias mv='mv --interactive --verbose'
|
||||
alias rm='rm -I --preserve-root --verbose'
|
||||
|
||||
|
||||
# Faster directory switching
|
||||
alias cd..='cd ..'
|
||||
alias ..='cd ..'
|
||||
alias ...='cd ../..'
|
||||
alias ....='cd ../../..'
|
||||
alias .....='cd ../../../..'
|
||||
|
||||
|
||||
# Convenient defaults
|
||||
alias mkdir='mkdir -p'
|
||||
alias md='mkdir'
|
||||
alias rmdir='rmdir --parents --verbose'
|
||||
alias rd='rmdir'
|
||||
|
||||
|
||||
# Convenient grepping
|
||||
alias grep='grep --color=auto --exclude-dir={.cache,\*.egg-info,.git,.nox,.tox,.venv}'
|
||||
alias egrep='egrep --color=auto --exclude-dir={.cache,\*.egg-info,.git,.nox,.tox,.venv}'
|
||||
alias fgrep='fgrep --color=auto --exclude-dir={.cache,*.egg-info,.git,.nox,.tox,.venv}'
|
||||
|
||||
|
||||
# Convenient searching
|
||||
alias fdir='find . -type d -name'
|
||||
alias ffile='find . -type f -name'
|
||||
|
||||
|
||||
# Convenient listings
|
||||
alias ls='ls --classify --color=auto --group-directories-first --human-readable --no-group --time-style=long-iso'
|
||||
alias la='ls --almost-all'
|
||||
alias lal='la -l'
|
||||
alias ll='ls -l'
|
||||
alias l.='ls --directory .*'
|
||||
alias ll.='l. -l'
|
||||
|
||||
|
||||
# More convenience with various other file-related utilities
|
||||
alias df='df --human-readable'
|
||||
alias du='du --human-readable'
|
||||
alias diff='diff --color=auto --unified'
|
||||
_command_exists colordiff && alias diff='colordiff --unified'
|
||||
alias free='free --human --total'
|
||||
alias less='less --chop-long-lines --ignore-case --LONG-PROMPT --no-init --status-column --quit-if-one-screen'
|
||||
alias more='less'
|
||||
alias tree='tree -C --dirsfirst'
|
||||
67
.config/shell/aliases.d/generic.sh
Normal file
67
.config/shell/aliases.d/generic.sh
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
# Generic shell aliases for bash and zsh
|
||||
|
||||
|
||||
_command_exists() {
|
||||
command -v "$1" 1>/dev/null 2>&1
|
||||
}
|
||||
|
||||
_in_zsh() {
|
||||
[ -n "$ZSH_VERSION" ]
|
||||
}
|
||||
|
||||
|
||||
# Re-run last command with sudo privileges
|
||||
if _in_zsh; then
|
||||
alias ,,='sudo $(fc -ln -1)'
|
||||
else
|
||||
alias ,,='sudo $(history -p !!)'
|
||||
fi
|
||||
|
||||
|
||||
# Convenient piping with zsh
|
||||
if _in_zsh; then
|
||||
alias -g B='| bat'
|
||||
alias -g F='| fzf'
|
||||
alias -g G='| grep'
|
||||
alias -g H='| head'
|
||||
alias -g L='| less'
|
||||
alias -g T='| tail'
|
||||
alias -g NE='2 > /dev/null'
|
||||
alias -g NUL='> /dev/null 2>&1'
|
||||
fi
|
||||
|
||||
|
||||
# (Non-)obvious synonyms
|
||||
alias cls='clear'
|
||||
alias help='man'
|
||||
|
||||
|
||||
# Various one-line utilities
|
||||
alias datetime='date +"%Y-%m-%d %H:%M:%S %z (%Z)"'
|
||||
alias datetime-iso='date --iso-8601=seconds'
|
||||
alias dotfiles='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
|
||||
alias external-ip="curl https://icanhazip.com"
|
||||
alias external-ip-alt="curl https://ipinfo.io/ip\?token=cfd78a97e15ebf && echo"
|
||||
alias external-ip-extended-infos="curl https://ipinfo.io/json\?token=cfd78a97e15ebf && echo"
|
||||
alias speedtest="curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/22210ca35228f0bbcef75a7c14587c4ecb875ab4/speedtest.py | python -"
|
||||
|
||||
|
||||
# Fix common typos
|
||||
_command_exists ifconfig && alias ipconfig='ifconfig'
|
||||
_command_exists R && alias r='R'
|
||||
|
||||
|
||||
# Use sane defaults
|
||||
_command_exists exa && alias exa='exa --group-directories-first --git --time-style=long-iso'
|
||||
_command_exists netstat && alias ports='netstat -tulanp'
|
||||
_command_exists screenfetch && alias screenfetch='screenfetch -n'
|
||||
alias uptime='uptime --pretty'
|
||||
alias wget='wget --continue'
|
||||
|
||||
|
||||
# Create shorter aliases for various utilities
|
||||
_command_exists batcat && alias bat='batcat'
|
||||
_command_exists fdfind && alias fd='fdfind'
|
||||
_command_exists neofetch && alias nf='neofetch'
|
||||
_command_exists ranger && alias rn='ranger'
|
||||
_command_exists screenfetch && alias sf='screenfetch'
|
||||
24
.config/shell/aliases.d/git.sh
Normal file
24
.config/shell/aliases.d/git.sh
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# All git aliases (with < 7 characters) become shell aliases with a "g" prefix
|
||||
|
||||
|
||||
_command_exists() {
|
||||
command -v "$1" 1>/dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
if _command_exists git; then
|
||||
alias g='git'
|
||||
|
||||
for al in $(git internal-aliases); do
|
||||
[ ${#al} -lt 7 ] && eval "alias g$al='git $al'"
|
||||
done
|
||||
|
||||
# Check if a 'main' branch exists in place of a 'master' branch
|
||||
git_main_branch() {
|
||||
if [[ -n "$(git branch --list main)" ]]; then
|
||||
echo 'main'
|
||||
else
|
||||
echo 'master'
|
||||
fi
|
||||
}
|
||||
fi
|
||||
25
.config/shell/aliases.d/python.sh
Normal file
25
.config/shell/aliases.d/python.sh
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Make working with Python more convenient
|
||||
|
||||
|
||||
_command_exists() {
|
||||
command -v "$1" 1>/dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
# Interactive shells
|
||||
alias py='python'
|
||||
alias bpy='bpython'
|
||||
alias ipy='ipython'
|
||||
|
||||
|
||||
if _command_exists poetry; then
|
||||
alias pr='poetry run'
|
||||
fi
|
||||
|
||||
|
||||
if _command_exists pyenv; then
|
||||
alias pyvenvs='pyenv virtualenvs --bare --skip-aliases'
|
||||
alias pyver='pyenv version'
|
||||
alias pyvers='pyenv versions --skip-aliases'
|
||||
alias pywhich='pyenv which'
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue