diff --git a/.bash_completion b/.bash_completion index 1fdc09b..4270820 100644 --- a/.bash_completion +++ b/.bash_completion @@ -6,4 +6,3 @@ if [[ -d ~/.bash_completion.d ]]; then [[ -f "$f" ]] && . "$f" done fi - diff --git a/.bash_profile b/.bash_profile index be69f23..a1c01a8 100644 --- a/.bash_profile +++ b/.bash_profile @@ -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 -# Run .bashrc +# Run .bashrc (contains bash settings and aliases) [[ -f ~/.bashrc ]] && . ~/.bashrc - diff --git a/.bashrc b/.bashrc index 708e743..762550e 100644 --- a/.bashrc +++ b/.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 @@ -15,24 +15,10 @@ export HISTFILESIZE=2000 export PROMPT_DIRTRIM=3 # Color output and default options -export TERM=xterm-color export GREP_OPTS='--color=auto' export LS_OPTS='--color=auto -hFN --group-directories-first' 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 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 la='ls -a' alias ll='ls -la' -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 ' - -# Shortcut for getting root shell -alias sui='sudo -i' - -# Push the queerfeminist agenda -alias woman='man' -alias enby='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 &) +# 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 "$@" } -# Wine aliases -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 -} +# (Other aliases are defined in .bashrc.d/10_common_aliases.sh etc.) # Load z [[ -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}" 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 [[ -f ~/.bashrc.local ]] && source ~/.bashrc.local # Clean up environment variables unset TRED TGREEN TBLUE TGREENB TCYANB TWHITEB TRESET - diff --git a/.bashrc.d/10_common_aliases.sh b/.bashrc.d/10_common_aliases.sh new file mode 100644 index 0000000..3816485 --- /dev/null +++ b/.bashrc.d/10_common_aliases.sh @@ -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 +} diff --git a/.bashrc.d/30_desktop.sh b/.bashrc.d/30_desktop.sh new file mode 100644 index 0000000..87b06b8 --- /dev/null +++ b/.bashrc.d/30_desktop.sh @@ -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' diff --git a/.profile b/.profile index 22ffd2a..93f775c 100644 --- a/.profile +++ b/.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 @@ -11,6 +9,7 @@ export GPG_TTY=$(tty) # Environment variables +export TERM=xterm-color export TERMINAL=mate-terminal export EDITOR=vim export BROWSER=firefox @@ -25,4 +24,3 @@ export WINEDLLOVERRIDES=winemenubuilder.exe=d # Include host-specific .profile [ -f ~/.profile.local ] && source ~/.profile.local -