workstation/roles/home-cli/files/shrc

264 lines
6.9 KiB
Text
Raw Normal View History

#!/bin/sh
umask 0022
set -o emacs
set -o noclobber
# Locale and language.
export LC_ALL=
export LANG="en_GB.UTF-8"
export LANGUAGE="en_GB:en"
export LC_ADDRESS="en_GB.UTF-8"
export LC_COLLATE="en_GB.UTF-8"
export LC_CTYPE="en_GB.UTF-8"
export LC_IDENTIFICATION="en_GB.UTF-8"
export LC_MEASUREMENT="en_GB.UTF-8"
export LC_MESSAGES="en_GB.UTF-8"
export LC_MONETARY="en_GB.UTF-8"
export LC_NAME="en_GB.UTF-8"
export LC_NUMERIC="en_GB.UTF-8"
export LC_PAPER="en_GB.UTF-8"
export LC_TELEPHONE="en_GB.UTF-8"
export LC_TIME="en_GB.UTF-8"
export PAPERSIZE="a4"
export TIME_STYLE="long-iso"
# Other exports.
2020-01-15 17:22:36 +00:00
export ANSIBLE_NOCOWS=1
export EDITOR=vi
export PYTHONWARNINGS="ignore::UserWarning"
2019-11-21 12:22:44 +00:00
PS1="$ "
2019-11-21 12:22:05 +00:00
if /bin/test -z "${HOST}"; then
HOST="$(hostname)"
fi
if /bin/test $(id -u) -eq 0; then
2020-01-27 19:07:14 +00:00
export PS1="${HOST%%.*}# "
else
2020-01-27 19:07:14 +00:00
export PS1="${HOST%%.*}$ "
fi
2019-11-21 12:22:05 +00:00
if [ "$BASH" ]; then
shopt -s histappend
bind '"\e[1;5C": forward-word'
bind '"\e[1;5D": backward-word'
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
fi
if [ "$ZSH_VERSION" ]; then
# Command history.
autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^[[A" history-beginning-search-backward-end
bindkey "^[[B" history-beginning-search-forward-end
bindkey "^[OA" history-beginning-search-backward-end
bindkey "^[OB" history-beginning-search-forward-end
bindkey "^[[1;5C" forward-word # Ctrl-Right
bindkey "^[[1;5D" backward-word # Ctrl-Left
bindkey "^[[3;5~" delete-char # Ctrl-Del
bindkey "^[[3~" delete-char # Del
export HISTFILE=$HOME/.zsh_history
export HISTSIZE=1000000
export SAVEHIST=1000000
setopt EXTENDED_HISTORY
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt PROMPT_SUBST
setopt SHARE_HISTORY
fi
LSOPTIONS="-F"
if ls --color=auto /dev/null 2>/dev/null 1>/dev/null; then
LSOPTIONS="$LSOPTIONS --color=auto"
fi
if [ "$(uname -s)" = "FreeBSD" ]; then
LSOPTIONS="$LSOPTIONS -G"
fi
2019-11-12 17:44:33 +00:00
if [ "$(uname -s)" = "Linux" ]; then
alias df="df -x squashfs"
fi
alias adoc="asciidoctor -a stylesheet=$HOME/.asciidoctor.css"
alias cal="ncal -w"
alias ec="emacsclient -c"
alias en="emacsclient -nw"
alias f="fossil"
alias ll="/bin/ls -l"
alias ls="/bin/ls $LSOPTIONS"
alias now="date +%Y%m%dT%H%M%S%z"
alias nowu="date -u +%Y%m%dT%H%M%SZ"
alias ta="$HOME/opt/textadept/textadept"
alias wgr="wordgrinder"
alias ytmp3="youtube-dl -q -x --audio-format=mp3"
# QEMU aliases
alias qemu-486="qemu-system-i386 -machine isapc,accel=kvm -cpu 486 -m 16 -vga cirrus -soundhw sb16 -nic none" # -nic user,model=ne2k_isa
alias qemu-p1="qemu-system-i386 -machine pc,accel=tcg -cpu pentium -m 64 -vga cirrus -soundhw sb16 -nic none" # -nic user,model=ne2k_isa
alias qemu-p3="qemu-system-i386 -machine pc,accel=kvm -cpu pentium3 -m 256 -vga cirrus -usb -soundhw sb16 -nic none" # -nic user,model=rtl8139
alias qemu-core2="qemu-system-x86_64 -machine q35,accel=kvm -cpu core2duo -m 2048 -vga qxl -usb -soundhw hda -nic none" # -nic user,model=e1000
if [ ! -d "$HOME/.local/bin" ]; then
/bin/mkdir -p "$HOME/.local/bin"
fi
# Alias vi to vim if it is installed
2019-11-28 16:14:47 +00:00
if [ -x /usr/bin/vim ] || [ -x /usr/local/bin/vim ] || [ -x /usr/pkg/bin/vim ]; then
alias vi="vim"
fi
# Set up GOPATH
export GOPATH="$HOME/data/go"
if [ -x /usr/bin/go ] || [ -x /usr/local/bin/go ]; then
if [ ! -d "$GOPATH" ]; then
/bin/mkdir -p "$GOPATH/bin"
/bin/mkdir -p "$GOPATH/pkg"
/bin/mkdir -p "$GOPATH/src"
fi
fi
# Useful aliases for Podman and Docker
alias prun="podman run --rm -it"
alias prunx="podman run -v /tmp/.X11-unix:/tmp/.X11-unix:ro -e DISPLAY=\"unix\$DISPLAY\""
alias drun="sudo docker run --rm -it"
alias drunx="sudo docker run -v /tmp/.X11-unix:/tmp/.X11-unix:ro -e DISPLAY=\"unix\$DISPLAY\""
2019-11-28 16:07:46 +00:00
PATH="/usr/sbin:/sbin:/usr/bin:/bin"
2019-11-22 15:49:15 +00:00
for dir in $HOME/bin \
$GOPATH/bin \
$HOME/.cargo/bin \
2019-11-23 13:48:36 +00:00
$HOME/.gem/ruby/2.6.0/bin \
/usr/X11R7/bin \
2019-11-22 15:49:15 +00:00
/usr/X11R6/bin \
/usr/local/sbin \
2019-11-22 15:49:15 +00:00
/usr/local/bin \
/usr/pkg/sbin \
2019-11-22 15:49:15 +00:00
/usr/pkg/bin \
/usr/games \
/usr/local/heirloom-doctools/bin \
2019-11-28 15:53:33 +00:00
/usr/pkg/heirloom-doctools/bin \
/var/lib/snapd/snap/bin \
2019-11-22 15:49:15 +00:00
/app/bin \
/snap/bin \
; do
if [ -d "$dir" ]; then
PATH="$PATH:$dir"
fi
done
export PATH
MANPATH="/usr/share/man"
for dir in $HOME/.local/share/man \
/usr/X11R6/man \
/usr/X11R7/man \
/usr/local/man \
/usr/pkg/man \
/usr/local/share/man \
/usr/local/heirloom-doctools/man \
; do
if [ -d "$dir" ]; then
MANPATH="$MANPATH:$dir"
fi
done
export MANPATH
mkcd () {
if [ $# -ne 1 ]; then
echo "mkcd: incorrect arguments (one directory required)." >&2
return 1
else
mkdir -p "$1"
cd "$1"
fi
}
termtitle () {
echo -en "\033]0;$1\007"
}
linapm () {
cat /sys/class/power_supply/BAT0/{status,capacity}
}
cman () {
# md: start bold
# us: start underline
# ue: end underline
# me: end bold, blink, and underline
env MANPAGER=less \
LESS_TERMCAP_md=$'\e[1;36m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_us=$'\e[4;32m' \
LESS_TERMCAP_ue=$'\e[0m' \
/usr/bin/man "$1"
}
xa () {
OUT=$(xrandr --listactivemonitors | awk 'NR!=1{print " "$NF" "}')
for monitor in "${OUT}"; do
m=$(echo $monitor | sed 's/ //g')
xrandr --output $m --auto
done
}
2019-12-16 15:15:49 +00:00
lastreboots () {
journalctl | grep -A 1 -- '-- Reboot --' | grep -v '^--' | awk '{print $1, $2, $3}'
}
2020-01-27 18:57:58 +00:00
emacsro () {
2020-01-25 17:01:01 +00:00
emacs $1 -f view-mode
}
2020-02-05 17:35:32 +00:00
tm () {
if tmux list-session 2>/dev/null 1>/dev/null; then
tmux -2 attach-session
else
tmux -2 new-session
fi
}
if [ -x /usr/bin/yum ] && [ ! -x /usr/bin/dnf ]; then
alias dnf='yum'
fi
if test -n "$DISPLAY" && test -x /usr/bin/subl; then
export EDITOR="/usr/bin/subl -nw"
fi
if [ -x /usr/bin/svnlite ] && [ ! -x /usr/local/bin/svn ]; then
alias svn='svnlite'
alias svnadmin='svnliteadmin'
alias svndumpfilter='svnlitedumpfilter'
alias svnlook='svnlitelook'
alias svnmucc='svnlitemucc'
alias svnrdump='svnliterdump'
alias svnserve='svnliteserve'
alias svnsync='svnlitesync'
alias svnversion='svnliteversion'
fi
case $- in
*i*)
# Shell is interactive
printf "\033[7m"
uname -sr
printf "\033[0m"
if [ -r /etc/os-release ]; then
echo " $(. /etc/os-release; echo $PRETTY_NAME)"
fi
;;
*)
;;
esac
2020-02-06 11:20:47 +00:00
if test -S "$SSH_AUTH_SOCK" && test -r "$HOME/.ssh/id_rsa" && [ $(ssh-add -l | grep "$HOME/.ssh/id_rsa" | wc -l) = 0 ]; then
ssh-add "$HOME/.ssh/id_rsa"
2020-02-05 15:38:15 +00:00
fi
if [ -r $HOME/.shrc.$(hostname -s) ]; then
. $HOME/.shrc.$(hostname -s)
fi