Dup Ver Goto 📝

my_bashrc

PT2/linux/shell does not exist
To
126 lines, 541 words, 3445 chars Page 'my_bashrc' does not exist.

I organise things into multiple .stuff files (see my stuff files, and then bash_common loads the ones I always want loaded. I put all my stuff that I want all users to be able to access in /usr/jda somewhere. (I tend to create a number of users so as to isolate projects and settings. See my etc skel. So my .bashrc is just

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

. /usr/jda/etc/bash_paths.bashrc

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# put things in ~/bin/my_stuff/
. /usr/jda/etc/bash_common.bashrc

then `/usr/jda/bash_paths

# bash_paths.bashrc -- run first to set PATH and similar
# this runs BEFORE we check to see if the shell is interactive or not.

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

PATH="$(tidypath -c "$HOME/bin:/usr/local/cygbin:/usr/jda/bin2:/usr/jda/bin:/usr/jda/bin0:/usr/npm/bin:$PATH:/usr/jda/stuff:/usr/apps:$HOME/perl5/bin")"
. pathif.stuff
export PYTHONPATH="$(tidypath -c "$HOME/.python:$PYTHONPATH")"
export VISUAL=vim EDITOR=vim

see below for tidypath, and note that things get very borked if this command is not in the PATH that bash starts with (so it is one of the few things I put in /usr/local/bin). So /usr/jda/etc/bash_common.bashrc is

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# this allows me to source a file iff it exists, and ignore silently if not.
# useful for things like `~/.cargo/env` which isn't there if I haven't
# installed rustup
.if() { for s; do [ -f "$s" ] && { . "$s"; }; done; }

# this is so I can type ".s t<TAB>" and get completion for .stuff files
.stuff() { 
  if [ $# = 0 ]; then
    ( cd /usr/jda/stuff; ls *.stuff | cut -f1 -d.; )
  else
    for s; do 
      [ -e /usr/jda/stuff/"$s".stuff ] && . /usr/jda/stuff/"$s".stuff; 
    done; 
  fi
}
alias .s=.stuff
. stuff_completion.stuff

. dot_commands.stuff # .w and friends
. dircolors.stuff
. completion.stuff
. cd.stuff
. mpd.stuff
. hist.stuff
. mvdesc.stuff
. filecmds.stuff
. cygwin.stuff
. antlr.stuff
. python.stuff
. x11.stuff
. shopt.stuff
. perl.stuff
. my_prompt
. my.stuff
. aliases.stuff
. browser.stuff

.if . "$HOME/.cargo/env"
PATH="$(tidypath -p)" # remove duplicates

Here is my collection of .stuff files.

Related commands

tidypath

#!/usr/bin/perl

use Cwd 'abs_path';

@p = ();
%p = ();
$conf = 1;

for(@ARGV) {
  if( /^-f$/ ) {
    # force inclusion of non-existent paths
    $conf = 0;
    next;
  }
  if( /^-p$/ ) {
    # splice in current PATH
    @a = split ":", $ENV{'PATH'};
    for $a(@a) {
      # force absolute paths (unless -f is active and a path does not exist
      if( -d "$a" ) { $a = abs_path($a); } elsif( $conf ) { next; }

      if( ! $p{$a} ) {
        push @p, $a;
        $p{$a} = 1;
      }
    }
    next
  } 
  @a = split ":";
  for $a(@a) {
    # force absolute paths (unless -f is active and a path does not exist
    if( -d "$a" ) { $a = abs_path($a); } elsif( $conf ) { next; }

    # add it if not already present
    if( ! $p{$a} ) {
      push @p, $a;
      $p{$a} = 1;
    }
  }
}

$path = join ":", @p;
print "$path\n";