title: My `.bashrc` tags: linux bash rc My `.bashrc` is quite an elaborate setup. I factor most things into files with a `.stuff` extension. I then put everything in a hierarchy somewhere, such as `/usr/jda` on my own machines, or `$HOME/jda` in other places (often I want all users to share the same config on personal machines, since all users are effectively me). The price is that shell startup takes half a second or so, and slightly longer with WSL. I split the `.bashrc` into two parts: one sets the paths, even if non-interactive. The other then does everything else once the interactive check has passed. ``` JDA=/usr/jda . "$JDA"/etc/bash_paths.bashrc # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac . "$JDA"/etc/bash_common.bashrc ``` ## `bash_paths.bashrc` The `tidypath` script removes non-existent directories and duplicate directories from the `PATH`. ``` # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples if [ -z "$JDA" ]; then export JDA=/usr/jda fi . "$JDA"/stuff/pathif.stuff for s in "$JDA"/stuff /usr/npm/bin "$JDA/private/bin" "$JDA/local/bin" "$JDA"/bin "$HOME/.local/bin" "$HOME"/bin; do if [[ "$s" =~ etc/$ ]]; then continue; fi pathif -p "$s" done for s in "$HOME/perl5/bin" "/usr/local/go/bin"; do pathif -a "$s" done export PYTHONPATH="$HOME/.python:$PYTHONPATH" if [ -x "$JDA/bin/tidypath" ]; then PYTHONPATH="$("$JDA/"bin/tidypath -c "$PYTHONPATH")" fi export VISUAL=vi EDITOR=vi ``` ## `bash_common.bashrc` ``` # make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" .if() { for s; do if [ -f "$s" ]; then . "$s"; fi; done; } .stuff() { if [ $# = 0 ]; then ( cd "$JDA"/stuff; ls *.stuff | cut -f1 -d.; ) else for s; do [ -e "$JDA"/stuff/"$s".stuff ] && . "$JDA"/stuff/"$s".stuff; done; fi } .catstuff() { for s; do [ -e "$JDA"/stuff/"$s".stuff ] && cat "$JDA"/stuff/"$s".stuff; done; } alias .s=.stuff .s cmds .s dircolors .s completion .s cd .s cdh .s zoxide .s mpd .s hist .s mvdesc .s cygwin .s git .s ssh .s antlr .s python .s x11 .s shopt .s perl .s stuff .s aliases .s dot_commands .s clip .s cargo .s nvm .s go .s tmux .s vim . my_prompt complete -c viw catw batw lessw # user-specific stuff in ~/bin/my_stuff.d/*.stuff .s my_stuff # ensure we got output from tidypath # if tidypath is not found, this will not set the PATH to the empty string NEWPATH="$("$JDA"/bin/tidypath "$PATH")" [ -n "$NEWPATH" ] && PATH="$NEWPATH" .if "$HOME/.bash_aliases" ```