Refactor .bashrc; add .bashrc.d drop-in files

This commit is contained in:
Lexi / Zoe 2021-05-28 19:31:58 +02:00
parent eec14ac25d
commit 5981b030c1
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
6 changed files with 135 additions and 122 deletions

View file

@ -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
}

18
.bashrc.d/30_desktop.sh Normal file
View file

@ -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'