aboutsummaryrefslogtreecommitdiff
path: root/.bashrc
blob: 8d9a9f58715e303c7f1f71ef6ea692393de9c88a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash -eu

# source exports
export BASH_PROFILE=1 && . "$HOME/.bash_profile"

# bail if not interactive
printf '%s' "$-" | grep -q "i" || return

# cd using directory name
shopt -s autocd

# append bash history entries
shopt -s histappend

# bash history one command per line
shopt -s cmdhist

# disable program completion
shopt -u progcomp

# enable vi mode
set -o vi

# disable ctrl+s
stty stop ''
stty start ''
stty -ixon
stty -ixoff

# fzf bindings
fzfcompletion="$HOME/.config/fzf/completion.bash"
fzfkeybindings="$HOME/.config/fzf/key-bindings.bash"
[ -f "$fzfcompletion" ] && . "$fzfcompletion"
[ -f "$fzfkeybindings" ] && . "$fzfkeybindings"

# set virtual console colors
if [ "$TERM" = "linux" ]; then
  echo -en "\e]P0111111" # black [background]
  echo -en "\e]P1D84F4F" # darkred
  echo -en "\e]P2DEFF3E" # darkgreen
  echo -en "\e]P3FFDF23" # brown
  echo -en "\e]P479AEFF" # darkblue
  echo -en "\e]P58894CF" # darkmagenta
  echo -en "\e]P679AEFF" # darkcyan
  echo -en "\e]P7dddddd" # lightgray
  echo -en "\e]P8DDDDDD" # darkgray
  echo -en "\e]P9E84F4F" # red
  echo -en "\e]PABEFF3E" # green
  echo -en "\e]PBFEA63C" # yellow
  echo -en "\e]PC69AEFF" # blue
  echo -en "\e]PD9894CF" # magenta
  echo -en "\e]PE69AEFF" # cyan
  echo -en "\e]PFffffff" # white [foreground]
  clear                  # for background artifacting
fi

# color man
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 "$@"
}

# ssh agent with keychain
alias ssh='eval $(keychain --dir $HOME/.cache/keychain --eval --agents ssh -Q --quiet ~/.ssh/mobile ~/.ssh/primary) && ssh'

# parenting
alias mv='mv -i'
alias cp='cp -i'
alias ln='ln -i'
alias rm='rm -I --preserve-root'
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'

# general aliases
alias alsamixer='alsamixer --view all'
alias archey3="archey3 --config=~/.config/archey3.cfg"
alias colortest='msgcat --color=test'
alias dash='PS1="$ " dash'
alias diceware='diceware -d " "'
alias dict='dict -h localhost'
alias dmesg='dmesg -e'
alias emacs='TERM=xterm-256color emacs -nw'
alias grep='grep --color=tty -d skip'
alias locate='locate -ie'
alias ls='ls -hN --color=always --group-directories-first'
alias lsblk='lsblk -o NAME,MAJ:MIN,RM,SIZE,FSTYPE,RO,TYPE,MOUNTPOINT,MODEL'
alias lxc-attach='lxc-attach --clear-env --name'
alias lxc-ls='lxc-ls --fancy'
alias lynx='lynx -cfg ~/.config/lynx/lynx.cfg'
alias newsboat='newsboat -c $XDG_CONFIG_HOME/newsboat/cache.db -u $XDG_CONFIG_HOME/newsboat/urls -C $XDG_CONFIG_HOME/newsboat/config'
alias nix-index='nix-index --db $XDG_DATA_HOME/nix-index'
alias nix-locate='nix-locate --db $XDG_DATA_HOME/nix-index'
alias rangerinf='while true; do ranger; done'
alias rofi='rofi -cache-dir $XDG_DATA_HOME'
alias sh='dash'
alias tidy='tidy -config $HOME/.config/tidy.conf'
alias units='units --history "$XDG_CACHE_HOME"/units_history'

# nix helpers
nix-which() { readlink --canonicalize "$(type -P "$1")"; }

# lxc helpers
lxc-copy() { A=$1 && B=$2 && shift 2 && $(type -P lxc-copy) --allowrunning --name "$A" -N "$B" "$@"; }
lxc-shell() { lxc-start "$1" > /dev/null 2>&1 && lxc-attach "$1" -- /bin/sh -c 'export HOME="/root" && . /etc/profile && /bin/sh'; }
lxc-restart() { $(type -P lxc-stop) --kill --name "$1"; $(type -P lxc-start) -n "$1"; }
lxc-start() { for container in "$@"; do $(type -P lxc-start) --name "$container"; done }
lxc-stop() { for container in "$@"; do $(type -P lxc-stop) --kill --name "$container"; done }
lxc-destroy() { for container in "$@"; do $(type -P lxc-destroy) --name "$container"; done }

# source fzf markers
[ -f "$HOME/.config/fzf/marks.plugin.bash" ] && . "$HOME/.config/fzf/marks.plugin.bash"

# extract docker container as rootfs
docker-rootfs() { id=$(docker run --detach "$1" /bin/true) \
  && docker export "$id" --output "rootfs.tar" \
  && docker container rm "$id" \
  && ls -l rootfs.tar; }

# press ctrl+d after writing string to standard input (https://til.simonwillison.net/bash/escaping-a-string)
shellquote() { printf '%q\n' "$(cat)"; }

# show window title of last command (https://stackoverflow.com/a/5080670)
trap 'echo -ne "\033]2;term: $PWD $(history 1 | tr -s " " | cut -d " " -f 5-)\007"' DEBUG

# swallow
swallow() { "$@" & disown; exit; }