Refactor .bashrc; add .bashrc.d drop-in files
This commit is contained in:
parent
eec14ac25d
commit
5981b030c1
|
|
@ -6,4 +6,3 @@ if [[ -d ~/.bash_completion.d ]]; then
|
||||||
[[ -f "$f" ]] && . "$f"
|
[[ -f "$f" ]] && . "$f"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
#
|
#
|
||||||
# ~/.bash_profile
|
# ~/.bash_profile -- Sourced by bash in login shells only
|
||||||
#
|
#
|
||||||
|
|
||||||
# Run .profile
|
# Include .profile (contains ENV variables)
|
||||||
[[ -f ~/.profile ]] && . ~/.profile
|
[[ -f ~/.profile ]] && . ~/.profile
|
||||||
|
|
||||||
# Run .bashrc
|
# Run .bashrc (contains bash settings and aliases)
|
||||||
[[ -f ~/.bashrc ]] && . ~/.bashrc
|
[[ -f ~/.bashrc ]] && . ~/.bashrc
|
||||||
|
|
||||||
|
|
|
||||||
133
.bashrc
133
.bashrc
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# ~/.bashrc -- global .bashrc, includes ~/.bashrc.local
|
# ~/.bashrc -- Sourced by bash in interactive non-login shells; includes ~/bashrc.d/* and ~/.bashrc.local
|
||||||
#
|
#
|
||||||
|
|
||||||
# If not running interactively, don't do anything
|
# If not running interactively, don't do anything
|
||||||
|
|
@ -15,24 +15,10 @@ export HISTFILESIZE=2000
|
||||||
export PROMPT_DIRTRIM=3
|
export PROMPT_DIRTRIM=3
|
||||||
|
|
||||||
# Color output and default options
|
# Color output and default options
|
||||||
export TERM=xterm-color
|
|
||||||
export GREP_OPTS='--color=auto'
|
export GREP_OPTS='--color=auto'
|
||||||
export LS_OPTS='--color=auto -hFN --group-directories-first'
|
export LS_OPTS='--color=auto -hFN --group-directories-first'
|
||||||
export LESS="-Ri"
|
export LESS="-Ri"
|
||||||
|
|
||||||
# Colored man pages
|
|
||||||
man() {
|
|
||||||
env \
|
|
||||||
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
|
|
||||||
LESS_TERMCAP_md=$(printf "\e[1;31m") \
|
|
||||||
LESS_TERMCAP_me=$(printf "\e[0m") \
|
|
||||||
LESS_TERMCAP_se=$(printf "\e[0m") \
|
|
||||||
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
|
|
||||||
LESS_TERMCAP_ue=$(printf "\e[0m") \
|
|
||||||
LESS_TERMCAP_us=$(printf "\e[1;32m") \
|
|
||||||
man "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# colored GCC warnings and errors
|
# colored GCC warnings and errors
|
||||||
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
|
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
|
||||||
|
|
||||||
|
|
@ -46,106 +32,21 @@ alias ip='ip -color=auto'
|
||||||
alias l='ls -l'
|
alias l='ls -l'
|
||||||
alias la='ls -a'
|
alias la='ls -a'
|
||||||
alias ll='ls -la'
|
alias ll='ls -la'
|
||||||
alias sorth='sort -hr'
|
|
||||||
alias ps-grep='ps -ef | grep'
|
|
||||||
|
|
||||||
# Alias expansion for sudo
|
# Colored man pages
|
||||||
# https://unix.stackexchange.com/questions/148545/why-does-sudo-ignore-aliases/148548#148548
|
man() {
|
||||||
alias sudo='sudo '
|
env \
|
||||||
|
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
|
||||||
# Shortcut for getting root shell
|
LESS_TERMCAP_md=$(printf "\e[1;31m") \
|
||||||
alias sui='sudo -i'
|
LESS_TERMCAP_me=$(printf "\e[0m") \
|
||||||
|
LESS_TERMCAP_se=$(printf "\e[0m") \
|
||||||
# Push the queerfeminist agenda
|
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
|
||||||
alias woman='man'
|
LESS_TERMCAP_ue=$(printf "\e[0m") \
|
||||||
alias enby='man'
|
LESS_TERMCAP_us=$(printf "\e[1;32m") \
|
||||||
|
man "$@"
|
||||||
# meow instead of ping
|
|
||||||
alias meow='ping'
|
|
||||||
|
|
||||||
# git shortcuts
|
|
||||||
alias git-stashpull="git stash && git pull && git stash pop"
|
|
||||||
|
|
||||||
# X application aliases
|
|
||||||
alias gvimr='gvim --remote-silent'
|
|
||||||
alias xclip_='xclip -selection clipboard'
|
|
||||||
|
|
||||||
# Open files according to MIME type
|
|
||||||
xo() {
|
|
||||||
(nohup mimeopen "$@" 2>/dev/null 1>&2 &)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wine aliases
|
# (Other aliases are defined in .bashrc.d/10_common_aliases.sh etc.)
|
||||||
alias wine32='env WINEARCH=win32 WINEPREFIX="$HOME/.wine32" wine'
|
|
||||||
|
|
||||||
alias youtube-dl-mp3='youtube-dl -x --audio-format mp3'
|
|
||||||
|
|
||||||
# termbin.com: terminal pastebin
|
|
||||||
alias termbin='nc termbin.com 9999'
|
|
||||||
|
|
||||||
# Stop Ctrl-S from doing terminally things in vim/vimdiff
|
|
||||||
vim() {
|
|
||||||
local STTYOPTS="$(stty --save)"
|
|
||||||
stty stop '' -ixoff
|
|
||||||
command vim "$@"
|
|
||||||
stty "$STTYOPTS"
|
|
||||||
}
|
|
||||||
|
|
||||||
vimdiff() {
|
|
||||||
local STTYOPTS="$(stty --save)"
|
|
||||||
stty stop '' -ixoff
|
|
||||||
command vimdiff "$@"
|
|
||||||
stty "$STTYOPTS"
|
|
||||||
}
|
|
||||||
|
|
||||||
# yay without parameters does "pacman -Syu" but I don't want it to do this
|
|
||||||
yay() {
|
|
||||||
[[ $# -gt 0 ]] || { echo "error: no operation specified (use -h for help)"; return 1; }
|
|
||||||
command yay "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create and cd to tmp dir
|
|
||||||
alias cdtmp='cd $(mktemp -d -p ~/tmp/)'
|
|
||||||
|
|
||||||
# Make dir and cd to it (from Mara)
|
|
||||||
function mkcd {
|
|
||||||
mkdir -p "$1"
|
|
||||||
cd "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
# cd to dir + ll (ls -la)
|
|
||||||
function cdll {
|
|
||||||
cd "$1"
|
|
||||||
ls -la
|
|
||||||
}
|
|
||||||
|
|
||||||
calc() {
|
|
||||||
echo "$@" | bc
|
|
||||||
}
|
|
||||||
|
|
||||||
# Show content of something, `ls` for dirs (and special files), `cat` for files
|
|
||||||
lscat() {
|
|
||||||
[[ $# -eq 0 ]] && ls -la && return
|
|
||||||
printnewline=""
|
|
||||||
for f in "$@"; do
|
|
||||||
[[ $printnewline ]] && echo
|
|
||||||
printnewline=1
|
|
||||||
if [[ -f $f ]]; then
|
|
||||||
[[ $# -gt 1 ]] && echo "-- cat \"$f\""
|
|
||||||
cat "$f"
|
|
||||||
else
|
|
||||||
[[ $# -gt 1 ]] && echo "-- ls \"$f\""
|
|
||||||
ls -la "$f"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Dump arguments with newlines and quotes
|
|
||||||
dumpargs() {
|
|
||||||
for a in "$@"; do
|
|
||||||
echo "\"$a\""
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load z
|
# Load z
|
||||||
[[ -r "/usr/share/z/z.sh" ]] && source /usr/share/z/z.sh
|
[[ -r "/usr/share/z/z.sh" ]] && source /usr/share/z/z.sh
|
||||||
|
|
@ -166,9 +67,15 @@ else
|
||||||
PS1="${TGREEN}\u@\h ${TBLUE}\w ${TWHITEB}\$ ${TRESET}"
|
PS1="${TGREEN}\u@\h ${TBLUE}\w ${TWHITEB}\$ ${TRESET}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Include drop-in files
|
||||||
|
if [[ -d ~/.bashrc.d ]]; then
|
||||||
|
for f in ~/.bashrc.d/*; do
|
||||||
|
[[ -f $f ]] && source "$f"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# Include host-specific bashrc
|
# Include host-specific bashrc
|
||||||
[[ -f ~/.bashrc.local ]] && source ~/.bashrc.local
|
[[ -f ~/.bashrc.local ]] && source ~/.bashrc.local
|
||||||
|
|
||||||
# Clean up environment variables
|
# Clean up environment variables
|
||||||
unset TRED TGREEN TBLUE TGREENB TCYANB TWHITEB TRESET
|
unset TRED TGREEN TBLUE TGREENB TCYANB TWHITEB TRESET
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
#
|
||||||
|
# ~/.bashrc.d/10_common_aliases.sh -- Collection of common bash aliases and functions
|
||||||
|
#
|
||||||
|
|
||||||
|
# Shortcut aliases
|
||||||
|
alias sorth='sort -hr'
|
||||||
|
alias ps-grep='ps -ef | grep'
|
||||||
|
|
||||||
|
# Alias expansion for sudo
|
||||||
|
# https://unix.stackexchange.com/questions/148545/why-does-sudo-ignore-aliases/148548#148548
|
||||||
|
alias sudo='sudo '
|
||||||
|
|
||||||
|
# sudo shortcuts for getting root shell or editing files
|
||||||
|
alias sui='sudo -i'
|
||||||
|
alias suvim='sudo -e'
|
||||||
|
|
||||||
|
# Stop Ctrl-S from doing terminally things in vim/vimdiff
|
||||||
|
vim() {
|
||||||
|
local STTYOPTS="$(stty --save)"
|
||||||
|
stty stop '' -ixoff
|
||||||
|
command vim "$@"
|
||||||
|
stty "$STTYOPTS"
|
||||||
|
}
|
||||||
|
|
||||||
|
vimdiff() {
|
||||||
|
local STTYOPTS="$(stty --save)"
|
||||||
|
stty stop '' -ixoff
|
||||||
|
command vimdiff "$@"
|
||||||
|
stty "$STTYOPTS"
|
||||||
|
}
|
||||||
|
|
||||||
|
# yay without parameters does "pacman -Syu" but I don't want it to do this
|
||||||
|
yay() {
|
||||||
|
[[ $# -gt 0 ]] || { echo "error: no operation specified (use -h for help)"; return 1; }
|
||||||
|
command yay "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create and cd to tmp dir
|
||||||
|
alias cdtmp='cd $(mktemp -d -p ~/tmp/)'
|
||||||
|
|
||||||
|
# Make dir and cd to it (from Mara)
|
||||||
|
function mkcd() {
|
||||||
|
mkdir -p "$1"
|
||||||
|
cd "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# cd to dir + ll (ls -la)
|
||||||
|
function cdll() {
|
||||||
|
cd "$1"
|
||||||
|
ls -la
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show content of something, `ls` for dirs (and special files), `cat` for files
|
||||||
|
function lscat() {
|
||||||
|
[[ $# -eq 0 ]] && ls -la && return
|
||||||
|
printnewline=""
|
||||||
|
for f in "$@"; do
|
||||||
|
[[ $printnewline ]] && echo
|
||||||
|
printnewline=1
|
||||||
|
if [[ -f $f ]]; then
|
||||||
|
[[ $# -gt 1 ]] && echo "-- cat \"$f\""
|
||||||
|
cat "$f"
|
||||||
|
else
|
||||||
|
[[ $# -gt 1 ]] && echo "-- ls \"$f\""
|
||||||
|
ls -la "$f"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function calc() {
|
||||||
|
echo "$@" | bc
|
||||||
|
}
|
||||||
|
|
||||||
|
# termbin.com: terminal pastebin
|
||||||
|
alias termbin='nc termbin.com 9999'
|
||||||
|
|
||||||
|
# Dump arguments with newlines and quotes
|
||||||
|
function dumpargs() {
|
||||||
|
for a in "$@"; do
|
||||||
|
echo "\"$a\""
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Shortcuts to encode/decode strings with base64
|
||||||
|
function b64enc() {
|
||||||
|
echo -n "$1" | base64 -w 0
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
function b64dec() {
|
||||||
|
echo -n "$1" | base64 -d
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
#
|
||||||
|
# ~/.bashrc.d/30_desktop.sh -- Aliases and functions for desktop environments
|
||||||
|
#
|
||||||
|
|
||||||
|
# Open files according to MIME type
|
||||||
|
xo() {
|
||||||
|
(nohup mimeopen "$@" 2>/dev/null 1>&2 &)
|
||||||
|
}
|
||||||
|
|
||||||
|
# X application aliases
|
||||||
|
alias gvimr='gvim --remote-silent'
|
||||||
|
alias xclip_='xclip -selection clipboard'
|
||||||
|
|
||||||
|
# Wine aliases
|
||||||
|
alias wine32='env WINEARCH=win32 WINEPREFIX="$HOME/.wine32" wine'
|
||||||
|
|
||||||
|
# Shortcut for youtube-dl
|
||||||
|
alias youtube-dl-mp3='youtube-dl -x --audio-format mp3'
|
||||||
6
.profile
6
.profile
|
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# ~/.profile (includes ~/.profile.local)
|
# ~/.profile -- Included by .bash_profile; includes ~/.profile.local
|
||||||
#
|
#
|
||||||
|
|
||||||
# SSH key agent is started by systemd user
|
# SSH key agent is started by systemd user
|
||||||
|
|
@ -11,6 +9,7 @@
|
||||||
export GPG_TTY=$(tty)
|
export GPG_TTY=$(tty)
|
||||||
|
|
||||||
# Environment variables
|
# Environment variables
|
||||||
|
export TERM=xterm-color
|
||||||
export TERMINAL=mate-terminal
|
export TERMINAL=mate-terminal
|
||||||
export EDITOR=vim
|
export EDITOR=vim
|
||||||
export BROWSER=firefox
|
export BROWSER=firefox
|
||||||
|
|
@ -25,4 +24,3 @@ export WINEDLLOVERRIDES=winemenubuilder.exe=d
|
||||||
|
|
||||||
# Include host-specific .profile
|
# Include host-specific .profile
|
||||||
[ -f ~/.profile.local ] && source ~/.profile.local
|
[ -f ~/.profile.local ] && source ~/.profile.local
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue