citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

.bashrc (7125B)


      1 # ~/.bashrc: executed by bash(1) for non-login shells.
      2 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
      3 # for examples
      4 set -o vi
      5 
      6 export LANGUAGE="en_US.UTF-8"
      7 export LANG="en_US.UTF-8"
      8 export LC_CTYPE="en_US.UTF-8"
      9 export NIXPKGS=$HOME/nixpkgs
     10 export NIX_PATH="nixpkgs=$NIXPKGS:$NIX_PATH"
     11 export NIX_PATH="nixos-config=$NIX_FILES:$NIX_PATH"
     12 export NIX_PATH="jb55pkgs=$HOME/etc/jb55pkgs:$NIX_PATH"
     13 export NIX_PATH="dotfiles=$HOME/dotfiles:$NIX_PATH"
     14 
     15 # If not running interactively, don't do anything
     16 #[ -z "$PS1" ] && return
     17 
     18 export HOST=$(hostname)
     19 export IGNORE_WINDOW_CHECK=1
     20 export LONG_RUNNING_COMMAND_TIMEOUT=3
     21 IN_NIX=""
     22 if [ -n "$IN_NIX_SHELL" ]; then
     23 	IN_NIX="-nix"
     24 fi
     25 export PS1='$(printf "\x01\033[30;1m\x02%3.*s\x01\033[0m\x02 %s%s> \x01\033[33m\x02" $? $? $HOST $IN_NIX)'
     26 export PS0='\033[0m'
     27 
     28 #export PS1='$(printf "\x01\033[30;1m\x02%3.*s\x01\033[0m\x02> " $? $?)'
     29 
     30 # don't put duplicate lines in the history. See bash(1) for more options
     31 #export HISTCONTROL=ignoredups
     32 # ... and ignore same sucessive entries.
     33 export HISTCONTROL=ignoreboth:erasedups
     34 export HISTSIZE=50000
     35 
     36 # check the window size after each command and, if necessary,
     37 # update the values of LINES and COLUMNS.
     38 shopt -s checkwinsize
     39 
     40 # OMG
     41 shopt -s histappend
     42 
     43 DIRCOLORS="$HOME/.dircolors"
     44 UNDISTRACT="$HOME/dotfiles/bash-undistract-me/undistract-me.sh"
     45 
     46 export PAGER="less"
     47 export LESS="-cix8RM --save-marks"
     48 
     49 TERM_THEME="dark"
     50 if [ -f ~/.Xresources.d/themes/current ]; then
     51 	TERM_THEME="$(basename $(readlink ~/.Xresources.d/themes/current))"
     52 fi
     53 
     54 # private stuff
     55 . ~/.bash_private
     56 
     57 if [ "$TERM_THEME" == "light" ]
     58 then
     59 	export BAT_THEME=GitHub
     60 else
     61 	export BAT_THEME=zenburn
     62 fi
     63 
     64 export NNCPCFG=~/.nncprc
     65 export PANDOC=pandoc-nice
     66 export MAIL=/home/jb55/var/notify/email-notify
     67 export MAILREADER=/run/current-system/sw/bin/neomutt
     68 export BAT_STYLE=plain
     69 export LPASS_HOME="$HOME/.config/lpass"
     70 export FUZZER=fzf
     71 export GOPHERCLIENT=vf1
     72 export GEMINICLIENT=av98
     73 export GOPHER=$GOPHERCLIENT
     74 export GNUPGHOME="$HOME/.gnupg"
     75 export SHAREFILE_HOST='charon:/www/cdn.jb55.com/s/'
     76 export SHAREFILE_URL='https://cdn.jb55.com/s/'
     77 export SHARE_SS_DIR="$HOME/var/img/ss"
     78 export DOTFILES=${DOTFILES:-$HOME/dotfiles}
     79 export VI_MODE=1
     80 export XZ=pxz
     81 export FZF_CTRL_R_OPTS="-e"
     82 export FZF_DEFAULT_OPTS="-e"
     83 export FZF_DEFAULT_COMMAND='rg --files --hidden'
     84 export EMACSCLIENT=edit
     85 
     86 # other
     87 export EDITOR="edit"
     88 export VISUAL="edit"
     89 export BROWSER="browser"
     90 export PAGER=less
     91 
     92 # go
     93 
     94 export GOPATH=$HOME/dev/gocode
     95 export PATH=$HOME/bin:$PATH
     96 export PATH=$HOME/.local/bin:$PATH
     97 export PATH=$HOME/.npm/bin:$PATH
     98 export PATH=$GOPATH/bin:$PATH
     99 
    100 md () {
    101     mandown README*
    102 }
    103 
    104 function f() {
    105 	eval "$(fuzz-run-command "$@")"
    106 }
    107 
    108 alias ag="ag --pager=less"
    109 alias attach="grabssh; screen -rD"
    110 alias awkt="awk -v FS=$'\t' -v OFS=$'\t'"
    111 alias catt="pygmentize -O style=monokai -f console256 -g"
    112 alias Ci="pcal interactive"
    113 alias clip="xclip -selection clipboard"
    114 alias C="pcal list"
    115 alias cpptags="ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++"
    116 alias crontab="VIM_CRONTAB=true crontab"
    117 alias cutt="cut -d $'\t' --output-delimiter=$'\t'"
    118 alias e="edit -n"
    119 alias emacs="env TERM=xterm-256color emacs"
    120 alias feh="feh --conversion-timeout 2"
    121 alias fixssh="source $HOME/bin/fixssh"
    122 #alias f=run_fuzzer
    123 alias fzf="fzf --exact"
    124 alias g=git
    125 alias githist="git reflog show | grep '}: commit' | nl | sort -nr | nl | sort -nr | cut --fields=1,3 | sed s/commit://g | sed -e 's/HEAD*@{[0-9]*}://g'"
    126 alias ibmgfx="cp437"
    127 alias info="info --vi-keys"
    128 alias jc="journalctl -u"
    129 alias jcu="journalctl --user -u"
    130 alias jsonpp="python -mjson.tool"
    131 alias ls="ls --color"
    132 alias m="neomutt"
    133 alias mq="msmtp-queue"
    134 alias mt="f nt query:today"
    135 alias myipaddress=myip
    136 alias myip="dig +short myip.opendns.com @resolver1.opendns.com"
    137 alias noder="env NODE_NO_READLINE=1 rlwrap node"
    138 alias nr="npm run"
    139 alias ns="nix-shell -p"
    140 alias page=$PAGER
    141 alias prettyjson=jsonpp
    142 alias qud="steam-run ~/.local/share/Steam/steamapps/common/Caves\ of\ Qud/CoQ.x86_64"
    143 alias scs="systemctl status"
    144 alias scsu="systemctl status --user"
    145 alias s="general-status"
    146 alias sorry='sudo $(fc -l -n -1)'
    147 alias tmuxa="tmux a -d -t "
    148 alias tmux="tmux -2"
    149 alias t="todo.sh"
    150 alias u="cd .."
    151 alias vim=nvim
    152 alias vless="/usr/share/vim/vim72/macros/less.sh"
    153 alias vnc_once="x11vnc -safer -nopw -once -display :0"
    154 alias wanip=myip
    155 alias wget="wget -c"
    156 alias xclip="xclip -selection clipboard"
    157 
    158 ghclone () {
    159   cd "$(gh-clone "$@")"
    160 }
    161 
    162 srhtclone () {
    163   cd "$(srht-clone "$@")"
    164 }
    165 
    166 cdnp () {
    167   nix-build '<nixpkgs>' --no-out-link -A "$1"
    168   cd $(nix-path "$1")
    169 }
    170 
    171 np () {
    172   nix-path "$1"
    173 }
    174 
    175 nsr () {
    176   local cmd="$1"
    177   shift
    178   nix-shell -p "$cmd" --run "$@"
    179 }
    180 
    181 nsr2 () {
    182     local cmd="$1"
    183     shift
    184     local cmd2="$(<<<"$cmd" rev | cut -d. -f1 | rev) $@"
    185     nsr "$cmd" "$cmd2"
    186 }
    187 
    188 nsc () {
    189   local cmd="$1"
    190   shift
    191   nix-shell -p "$cmd" --command "$@"
    192 }
    193 
    194 share () {
    195   sharefile "$@" | xclip
    196 }
    197 
    198 sharess () {
    199   share_last_ss | xclip
    200 }
    201 
    202 lt () {
    203   ls -ltah "$@" | "$PAGER"
    204 }
    205 
    206 lt1 () {
    207   res=$(\ls -1 -t "$@" | head -n1)
    208   xclip <<<"$res"
    209   printf '%s\n' "$res"
    210 }
    211 
    212 mv1 () {
    213   mv $(lt1 | stripansi) "$@"
    214 }
    215 
    216 pcsv () {
    217   csv-delim "$@" | pcsvt
    218 }
    219 
    220 pcsvt () {
    221   columnt "$@" | cat -n | less -R -S
    222 }
    223 
    224 header() {
    225   headers "${2:-/dev/stdin}" | grep "$1" | cutt -f1 | sed -E 's,^[ ]*,,g'
    226 }
    227 
    228 nsum() {
    229   awkt '{total = total + $1}END{print total}'
    230 }
    231 
    232 sumcol() {
    233   cut -f "$1" | nsum
    234 }
    235 
    236 uniqc() {
    237   sort "$@" | uniq -c | sort -nr
    238 }
    239 
    240 cdl () {
    241   cd "$(dirname "$(readlink -f "$(which "$1")")")"
    242 }
    243 
    244 env-type () {
    245   envtype="$1"
    246   shift
    247   nix-shell -Q -p $envtype "$@"
    248 }
    249 
    250 haskell-env () {
    251   env-type "haskellEnv" "$@"
    252 }
    253 
    254 haskell-env-hoogle () {
    255   env-type "haskellEnvHoogle" "$@"
    256 }
    257 
    258 haskell-env-tools() {
    259   env-type "haskellTools" "$@"
    260 }
    261 
    262 build-nix-cache() {
    263   nix-env -f "$NIXPKGS" -qaP \* > ~/.nixenv.cache
    264 }
    265 
    266 haskell-shell() {
    267   nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [$*])"
    268 }
    269 
    270 nix-path() {
    271   nix-instantiate --eval --expr 'with import <nixpkgs> {}; "${'"$1"'}"' | sed 's/"//g'
    272 }
    273 
    274 vnc-once() {
    275   x11vnc -safer -nopw -once -display ':0' "$1"
    276 }
    277 
    278 sql_wineparty() {
    279   export CS='postgres://wineparty.xyz/wineparty'
    280   export PG_USER='jb55'
    281 }
    282 
    283 sql_() {
    284   local query="$1"
    285   local args=("-U" "$pg_user" -A)
    286   if [ ! -z "$query" ];
    287   then
    288     args+=(-c "$query")
    289   fi
    290   psql -F $'\t' "${args[@]}"
    291 }
    292 
    293 sql() {
    294   sql_ "$@" -t | pcsvt
    295 }
    296 
    297 # fzf
    298 source $DOTFILES/.fzf_helpers
    299 
    300 # z
    301 source $HOME/bin/z.sh
    302 
    303 [ -e "$DIRCOLORS" ] && eval "$(dircolors -b "$DIRCOLORS")"
    304 [ -f ~/.fzf.bash ] && source ~/.fzf.bash
    305 [ -f ~/bin/z.sh ] && source ~/bin/z.sh
    306 [ -f "$UNDISTRACT" ] && source "$UNDISTRACT"
    307 
    308 eval "$(/run/current-system/sw/bin/direnv hook bash)"
    309 
    310 # needed for the C-h binding
    311 bind '"\C-x\C-a": vi-movement-mode'
    312 bind '"\C-x\C-e": shell-expand-line'
    313 bind '"\C-x\C-r": redraw-current-line'
    314 bind '"\C-x^": history-expand-line'
    315 
    316 bind '"\C-f": "`fuzz-run-command`\C-x\C-e"'
    317 bind -m vi-command '"\C-f": "i\C-f"'
    318 bind '"\C-g": "`fuzz-run-command sh`\C-x\C-e"'
    319 bind -m vi-command '"\C-h": "i\C-h"'
    320 bind '"\C-e": "!!\C-x\C-e"'
    321 bind -m vi-command '"\C-e": "i\C-e"'
    322 bind '"\C-l":clear-screen'
    323 
    324