Browse Source

Switch to org-generated .bashrc

George Jones 3 years ago
parent
commit
66d39a54c2
3 changed files with 750 additions and 500 deletions
  1. 279 483
      .bashrc
  2. 17 17
      .bashrc.org
  3. 454 0
      .bashrc.pre-org

+ 279 - 483
.bashrc

@@ -1,499 +1,295 @@
-#
-# GMJ .bashrc
-#
-# Tue Mar 26 20:07:29 2013
-#
-#
-# Don't do this unless you are testing.
-#
-#    set -e
-#
-#
-
-# Helper functions
-#PROG=`basename "$0" | tr -d '\n'`
-PROG="bashrc"
-
-function info()  { echo ${PROG}\: info: "$@" 1>&2; }
-function warn()  { echo ${PROG}\: warning: "$@" 1>&2; }
-function error() { echo ${PROG}\: error: "$@" 1>&2; }
-function debug() { [[ -v DEBUG ]] && echo ${PROG}\: debug: "$@" 1>&2 || true ; }
-function die()   { echo ${PROG}\: fatal: "$@" 1>&2 && exit 1; }
-
-#
-# Generic things
-#
+  #PROG=`basename "$0" | tr -d '\n'`  # normal setting
+  PROG="bashrc" # setting for bashrc due to errors
 
+  function info()  { echo ${PROG}\: info: "$@" 1>&2; }
+  function warn()  { echo ${PROG}\: warning: "$@" 1>&2; }
+  function error() { echo ${PROG}\: error: "$@" 1>&2; }
+  function debug() { [[ -v DEBUG ]] && echo ${PROG}\: debug: "$@" 1>&2 || true ; }
+  function die()   { echo ${PROG}\: fatal: "$@" 1>&2 && exit 1; }
 
 export PS1="\# [\t] \u@\h \W/ $ "
 
-#bind -x '"\C-l": clear;'
-alias rm='	rm -i'
-alias ag='	alias | grep -i'
-alias eg='	printenv | grep -i'
-alias hg='	history | grep -i'
-alias ht='	history | tail'
-alias fpg='	find . -print | egrep -i'
-alias egi='	egrep -i'
-alias oi='      offlineimap'
-alias psg='	/bin/ps -auxww | grep'
-alias p8='	ping -c 3 8.8.8.8' # make sure routing works
-alias pp='	ping -c 3 port111.com' # make sure dns and routing work
-alias locate='locate -r'
-
-#
-# cd functions that list the directory stack
-#
-
-function dirl() {
-    # "DIR"ectory "L"ist directory stack, one per line
-    # Usage: dirl
-
-    for d in `dirs`; do echo $d; done
-}
-
-function dirc() {
-    # "DIR"ectory "C"onnect - connect to directory and list stack
-    # Usage: dirc [DIR
-
-    pushd ${1:-"$HOME"} > /dev/null
-    dirl
-}
-
-function dirp () {
-    # "DIR"ectory "P"op - pop N entries off the directory stack
-    # Usage: dirp [N]
-    #
-    # OLD:
-    #   alias  dirp='popd > /dev/null && dirl'
-    for i in `seq ${1:-"1"}`; do
-        debug "dirl: popd. i is $i"
-        popd > /dev/null;
-    done
-    dirl
-}
-
-alias cd=dirc
-
-#
-# aliases (functions) that take args
-#
-
-function gf() {
-    # grep-find: grep for patterins in files via find
-    #
-    # Usage: gf patterns [files [days]]
-    #
-    # Examples:
-    #   gf findMeAnywhere
-    #   gf findMeInTextFiles '*.txt'
-    #   gf findMeInTextFiles .txt
-    #   gf BEGIN\|END .org 30
-
-    local files=""
-    local days="365"
-
-    set -o noglob
-
-    # $1 is pattern(s) for egrep
-    if [ -z ${1+x} ]; then
-        echo 'gf needs string(s) to search for ' 1>&2
-        info "Usage: gf patterns [files [days]]"
-        return 1
+  alias rm='	rm -i'
+  alias ag='	alias | grep -i'
+  alias eg='	printenv | grep -i'
+  alias hg='	history | grep -i'
+  alias ht='	history | tail'
+  alias fpg='	find . -print | egrep -i'
+  alias egi='	egrep -i'
+  alias psg='	/bin/ps -auxww | grep'
+  alias p8='	ping -c 3 8.8.8.8' # make sure routing works
+  alias pp='	ping -c 3 port111.com' # make sure dns and routing work
+  alias locate='locate -r'
+
+  function dirl() {
+      # "DIR"ectory "L"ist directory stack, one per line
+      # Usage: dirl
+
+      for d in `dirs`; do echo $d; done
+  }
+
+  function dirc() {
+      # "DIR"ectory "C"onnect - connect to directory and list stack
+      # Usage: dirc [DIR
+
+      pushd ${1:-"$HOME"} > /dev/null
+      dirl
+  }
+
+  function dirp () {
+      # "DIR"ectory "P"op - pop N entries off the directory stack
+      # Usage: dirp [N]
+      #
+      # OLD:
+      #   alias  dirp='popd > /dev/null && dirl'
+      for i in `seq ${1:-"1"}`; do
+          debug "dirl: popd. i is $i"
+          popd > /dev/null;
+      done
+      dirl
+  }
+
+  alias cd=pushd
+
+  function gf() {
+  # grep-find: grep for patterins in files via find
+  #
+  # Usage: gf patterns [files [days]]
+  #
+  # Examples:
+  #   gf findMeAnywhere
+  #   gf findMeInTextFiles '*.txt'
+  #   gf findMeInTextFiles .txt
+  #   gf BEGIN\|END .org 30
+
+  local files=""
+  local days="365"
+
+  set -o noglob
+
+  # First arg is pattern(s) for egrep
+  if [ -z ${1+x} ]; then
+    echo 'gf needs string(s) to search for ' 1>&2
+    info "Usage: gf patterns [files [days]]"
+    return 1
+  fi
+
+  # Second arg (if present) is files for find.  No globbing, so "*.txt" OK
+  if [ ! -z ${2+x} ]; then
+    if [[ "$2" =~ ^\. ]]; then
+      # Special case: treat ".foo" as "*.foo"
+      # Avoids needing to quote on command line
+      files="-name *$2"
+    else
+      files="-name ${2}"
     fi
+  fi
+
+  # $3 (if present) is find -mtime arg, default 365
+  if [ ! -z ${3+x} ]; then
+    days="${3}"
+  fi
+
+  # set -x
+  find . -type f -mtime -${days} $files -exec egrep --color -H -i "${1}" \{\} \;
+  # set +x
+
+  set +o noglob
+  }
+
+  # Preserve history across sesssions
+  #
+  # http://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows
+  #
+  export HISTCONTROL=ignoredups:erasedups  # no duplicate entries
+  export HISTSIZE=100000                   # big big history
+  export HISTFILESIZE=100000               # big big history
+  shopt -s histappend                      # append to history, don't overwrite it
+
+  # Save and reload the history after each command finishes
+  export PROMPT_COMMAND="history -a; history -c; history -r;"
+
+
+  function hgt() {
+      # hgt == "history grep (for arg) tail"
+      #echo "Histroy Grep tail"
+
+      if [ -z ${1+x} ]; then
+          echo 'hgt needs an argument' 1>&2
+          return 1
+      fi
+
+      history | grep -i "$1" | tail
+      return 0
+  }
+
+   if [ -e ${HOME}/etc/hostname ]; then
+       export HOSTNAME=`cat ${HOME}/etc/hostname`
+   elif [ -e /etc/hostname ]; then
+       export HOSTNAME=`cat /etc/hostname`
+   else
+       export HOSTNAME="unknown"
+   fi
+
+   # Set timezone if ~/bin/tz.sh exists
+
+   # NEW, if neeeed?
+   #
+   # https://linuxize.com/post/how-to-set-or-change-timezone-in-linux/
+   #
+   # OLD:
+   #
+   # if [ -e ~/bin/tz.sh ]; then
+   #     echo Setting timezone.
+   #     source ~/bin/tz.sh # should be in ~/rc.local
+   # fi
+
+   # STILL NEEDED?
+   #
+   # Set local for numeric output
+   LOCAL=`locale -a | grep -i en_us | head -1`
+   if [[ "$LOCAL" != "" ]]; then export LC_NUMERIC="$LOCAL"; fi
+
+   if [ -e ~/bin/sshagent ]; then
+       source ~/bin/sshagent
+   fi
+
+   if [[ "$OSTYPE" == "linux-gnu"* ]]; then
+     alias 2clip='xclip -selection c'
+     alias 3clip='printf %s "$(cat /dev/stdin)" | xclip -selection c'  # no final \n
+   elif [[ "$OSTYPE" == "darwin"* ]]; then
+     alias 2clip='pbcopy'
+   fi
+
+  pathrm() {
+      # remove an item from the path
+      if [ -d "$1" ]; then
+          removeThis="`echo $1 | sed -e 's#/#\\\/#'g`"
+          newPath=`echo $PATH | awk -v RS=: -v ORS=: "/$removeThis/ {next} {print}" | sed 's/[ :]*$//g'`
+          export PATH=$newPath
+      fi
+  }
+
+
+  pathlast() {
+      # add path to the end if not there
+      if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
+          export PATH="${PATH:+"$PATH:"}$1"
+      fi
+  }
+
+
+  pathfirst() {
+      # add path to the front if not there
+      if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
+          export PATH="$1:${PATH}"
+      fi
+  }
+
+  path() {
+    # show path
+    echo $PATH
+  }
 
-    # $2 (if present) is files for find.  No globbing, so "*.txt" OK
-    if [ ! -z ${2+x} ]; then
-        if [[ "$2" =~ ^\. ]]; then
-            # Special case: treat ".foo" as "*.foo"
-            # Avoids needing to quote on command line
-            files="-name *$2"
-        else
-            files="-name ${2}"
-        fi
-    fi
+  # show path, one entry per line
+  alias pathcat="echo $PATH | sed 's/:/\n/g'"
 
-    # $3 (if present) is find -mtime arg, default 365
-    if [ ! -z ${3+x} ]; then
-        days="${3}"
-    fi
 
-    # set -x
-    find . -type f -mtime -${days} $files -exec egrep --color -H -i "${1}" \{\} \;
-    # set +x
+  # Be sure we have a few specific paths if they exist
 
-    set +o noglob
-}
+  pathlast $HOME/bin
+  pathlast /usr/local/bin
+  pathlast /opt/bin
 
-function hgt() {
-    # hgt == "history grep (for arg) tail"
-    #echo "Histroy Grep tail"
+   if [ -d ${HOME}/rc.local ]; then
+       for rcfile in $(find ${HOME}/rc.local -name \*.sh); do
+           debug running localrc ${rcfile}
+           source ${rcfile}
+       done
+   fi
 
-    if [ -z ${1+x} ]; then
-        echo 'hgt needs an argument' 1>&2
-        return 1
-    fi
+   alias emacs='setsid emacs'
 
-    history | grep -i "$1" | tail
-    return 0
-}
-
-
-# Set HOSTNAME if ~/etc/hostname exists
-
-if [ -e ${HOME}/etc/hostname ]; then
-    export HOSTNAME=`cat ${HOME}/etc/hostname`
-elif [ -e /etc/hostname ]; then
-    export HOSTNAME=`cat /etc/hostname`
-else
-    export HOSTNAME="unknown"
-fi
-
-
-
-# Set timezone if ~/bin/tz.sh exists
-
-if [ -e ~/bin/tz.sh ]; then
-  echo Setting timezone.
-  source ~/bin/tz.sh
-fi
-
-# Set local for numeric output
-LOCAL=`locale -a | grep -i en_us | head -1`
-if [[ "$LOCAL" != "" ]]; then export LC_NUMERIC="$LOCAL"; fi
-
-# set up ssh agent
-#
-# Add keys by hand if needed via
-#
-#   ssh-add ~/.ssh/id_*
-
-if [ -e ~/bin/sshagent ]; then
-  #echo Starting SSH agent
-  source ~/bin/sshagent
-fi
-
-#
-# Because MacOS has to be different...
-#
-
-if [[ "$OSTYPE" == "linux-gnu"* ]]; then
-    # ...
-    alias 2clip='xclip -selection c'
-    alias 3clip='printf %s "$(cat /dev/stdin)" | xclip -selection c'  # no final \n
-elif [[ "$OSTYPE" == "darwin"* ]]; then
-        alias 2clip='pbcopy'
-fi
-# because hosnames assigned by IT deperments like abc123456789ef are not meaningful
-
-# Preserve history across sesssions
-#
-# http://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows
-#
-export HISTCONTROL=ignoredups:erasedups  # no duplicate entries
-export HISTSIZE=100000                   # big big history
-export HISTFILESIZE=100000               # big big history
-shopt -s histappend                      # append to history, don't overwrite it
-
-# Save and reload the history after each command finishes
-#export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
-export PROMPT_COMMAND="history -a; history -c; history -r;"
-
-# Useful functions
-
-# remove an item from the path
-pathrm() {
-    if [ -d "$1" ]; then
-        #echo 1 $1
-        removeThis="`echo $1 | sed -e 's#/#\\\/#'g`"
-        newPath=`echo $PATH | awk -v RS=: -v ORS=: "/$removeThis/ {next} {print}" | sed 's/[ :]*$//g'`
-        export PATH=$newPath
-    fi
-}
+   # from http://stuff-things.net/2014/12/16/working-with-emacsclient/
 
+   if [ -z "$SSH_CONNECTION" ]; then
+       export EMACSCLIENT=emacsclient
+       alias ec="$EMACSCLIENT -c -n"
+       export EDITOR="$EMACSCLIENT -c"
+       export ALTERNATE_EDITOR=""
+   else
+       export EDITOR=$(type -P emacs || type -P ed)
+   fi
+   export VISUAL=$EDITOR
 
-# add path to the end if not there
-pathlast() {
-    if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
-        #echo  pathlast $1
-        export PATH="${PATH:+"$PATH:"}$1"
-    fi
-}
+   # coloring for ls functions
 
-# add path to the front if not there
-pathfirst() {
-    if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
-        #echo  pathfirst $1
-        export PATH="$1:${PATH}"
-    fi
-}
+   if [[ "$OSTYPE" == "linux-gnu" ]]; then
+       color="--color";
+   else
+       color=""
+   fi
 
-# show path
-path() {
-    echo $PATH
-}
-
-# show path, one entry per line
-alias pathcat="echo $PATH | sed 's/:/\n/g'"
-
-
-# Be sure we have a few specific paths if they exist
-
-pathlast $HOME/bin
-pathlast /opt/bin
-pathlast /usr/local/bin
-pathlast /opt/bin
-
-#
-# Execute any .sh files in ~/rc.local/*.sh
-#
-# This allows me to split out setup for aliases
-# and commands that only get used on certian systems
-# or in certian contexts (git, go, mail, blog..)
-
-if [ -d ${HOME}/rc.local ]; then
-    for rcfile in $(find ${HOME}/rc.local -name \*.sh); do
-        #echo running localrc ${rcfile}
-        source ${rcfile}
-    done
-fi
-
-#
-# Invoking emacs
-#
-
-alias emacs='setsid emacs'
-
-# from http://stuff-things.net/2014/12/16/working-with-emacsclient/
-
-if [ -z "$SSH_CONNECTION" ]; then
-   export EMACSCLIENT=emacsclient
-   alias ec="$EMACSCLIENT -c -n"
-   export EDITOR="$EMACSCLIENT -c"
-   export ALTERNATE_EDITOR=""
-else
-    export EDITOR=$(type -P emacs || type -P ed)
-fi
-export VISUAL=$EDITOR
-
-# http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
-
-#    if hash emacsclient 2>/dev/null; then
-#        # http://stackoverflow.com/questions/5570451/how-to-start-emacs-server-only-if-it-is-not-started
-#        export ALTERNATE_EDITOR="" # Because I should never have to start emacs
-#	export VISUAL="emacsclient -t"
-#	export EDITOR="emacsclient -t"
-#	alias e='[ "$DISPLAY" == ""] && emacsclient -t || emacsclient -c'
-#    elif hash emacs 2>/dev/null; then
-#        export ALTERNATE_EDITOR="" # Because I should never have to start emacs
-#	export VISUAL="emacs"
-#	export EDITOR="emacs"
-#	alias e='[ "$DISPLAY" == ""] && emacsclient -t || emacsclient -c'
-#    else
-#        2>& echo BOO no emacs here
-#        export ALTERNATE_EDITOR="" # Because I should never have to start emacs
-#	export VISUAL=""
-#	export EDITOR=""
-#	unalias e 2>/dev/null || true
-#
-#    fi
-
-
-#
-# Do OS-specific setup
-#
-
-
-#
-# ls aliases
-#
-
-# coloring for ls functions
-
-if [[ "$OSTYPE" == "linux-gnu" ]]; then
-    # This works on terminals, piped to cat, tail etc
-    # This fails piped to more, less etc
-    # color="--color";
-    #
-    # Always omits color
-    # color="--color=never"
-    #
-    # This works when piped to less, more
-    # color="--color=auto"
-    #
-    # Probably want different settings of 'color='
-    # based on intend output (terminal, more/less).
-    #
-    # Need to fix/test this gmj <2018-05-18>
-
-     color="--color";
-    #color=""
-else
-    color=""
-fi
-
-BIN_LS=/bin/ls
-
-
-alias ls='	ls '$color' -a'
-
-
-
-#
-# NOTE/TODO: <2018-07-10> commented out function versions of ls
-# commands were an attempt at allowing different versions of ls
-# for directories other than $PWD.  Needs work.  "ls *" fails.
-#
-
-# List
-# Usage: ls [DIR]
-# function ls {
-#     DIR=${1:-.};
-#     $BIN_LS $color -a $DIR;
-# }
-
-
-#alias llrt='	ls -ltr '$color' -a | tail'
-# Long List Reverse Tail
-# Usage: llrt [DIR]
-# function llrt {
-#     DIR=${1:-.};
-#     $BIN_LS $color -a -ltr $DIR | tail
-# }
-unalias llrt 2> /dev/null
-function llrt() { ls -lrt $color ${*:-}; }
-
-#alias llt='	ls -lt '$color' -a'
-# Long List Time
-# Usage: llt [DIR]
-# function llt {
-#     set -x
-#     echo LLT2
-#     DIR=${1:-.}
-#     $BIN_LS $color -a -lt $DIR
-#     set +x
-# }
-unalias llt 2> /dev/null
-function llt() { ls -lt $color ${*:-}; }
-
-#alias lltm='	ls '$color' -a -lt | more'
-# Long List Time, More
-# Usage: lltm [DIR]
-# function lltm {
-#     DIR=${1:-.};
-#     $BIN_LS $color -a -lt $DIR | more;
-# }
-unalias llm 2> /dev/null
-function lltm() { ls -lt $color ${*:-} | more; }
-
-# alias lltl='	ls '$color' -a -lt | less'
-# Long List Time, Less
-# Usage: lltl [DIR]
-# function lltl {
-#     DIR=${1:-.};
-#     $BIN_LS $color -a -lt $DIR | less;
-# }
-unalias lltl 2> /dev/null
-function lltl() { ls -alt $color ${*:-} | more; }
-
-#alias llth='	ls '$color' -a -lt | head'
-# Long List Time, Head
-# Usage: llth [DIR [LINES]]
-# function llth {
-#     DIR=${1:-.};
-#     LINES=${2:-10};
-#     $BIN_LS $color -a -lt $DIR | head -$LINES;
-# }
-function llth() { ls -lt $color ${*:-} | head; }
-
-# alias lltt='	ls '$color' -a -lt | tail'
-# Long List Time, Tail
-# Usage: lltt [DIR [LINES]]
-# function lltt {
-#     DIR=${1:-.};
-#     LINES=${2:-10};
-#     $BIN_LS $color -a -lt $DIR | tail -$LINES;
-# }
-unalias lltt 2> /dev/null
-function lltt() { ls -alt $color ${*:-} | tail; }
-
-
-#alias lss='	ls '$color' -a -1s | sort -n'
-# List Sort Size
-# Usage: lss [DIR]
-# function lss {
-#     DIR=${1:-.};
-#     $BIN_LS $color -a -1s $DIR | sort -n
-# }
-unalias lss 2> /dev/null
-function lss() { ls -a1s $color ${*:-} | sort -n; }
-
-
-#alias lssr='	ls '$color' -a -1s | sort -nr'
-# List Sort Size Reverse
-# Usage: lssr [DIR]
-# function lssr {
-#     DIR=${1:-.};
-#     $BIN_LS $color -a -1s $DIR | sort -nr
-# }
-unalias lssr 2> /dev/null
-function lssr() { ls -a1s $color ${*:-} | sort -nr; }
-
-#
-# Aliases for viewing the newest file in a directoy
-#
-
-# list the newest file in the current directory
-# TODO: need to handle spaces in filenames
-
-function nf ()
-{
-    NF=`find ${1:-.} -maxdepth 1 -type f -print0 | xargs -0 ls -1t  |  head -1;`;
-    echo ${NF:-/dev/null} | sed "s/ /\\\ /g"
-}
-
-#alias nftf='tail -f `nf`' # tail follow newest file
-unalias nfh 2> /dev/null
-function nftf { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs tail -f  ; }
-
-#alias nft='tail `nf`'    # tail newest file
-unalias nft 2> /dev/null
-function nft { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs tail  ; }
-
-#alias nfh='head `nf`'    # head newest file
-unalias nfh 2> /dev/null
-function nfh { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs head  ; }
-
-#alias nfl='less `nf`'    # less newest file
-unalias nfl 2> /dev/null
-function nfl { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs less  ; }
-
-#alias nfc='cat `nf`'     # cat newest file
-unalias nfc 2> /dev/null
-function nfc { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs cat  ; }
-
-#alias nfls='ls -A1t `nf`'  # ls newest file, excluding .
-unalias nfls 2> /dev/null
-function nfls { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs ls -A1t  ; }
-
-#alias nflsl='ls -Atl `nf`' # ls newest file, long
-unalias nflsl 2> /dev/null
-function nflsl { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs ls -Atl  ; }
-
-
-# alias for viewing files
-#
-#  Notes on setting up file/mime type assiciatons
-#  https://unix.stackexchange.com/questions/77136/xdg-open-default-applications-behavior
-#
-#  So...
-#
-#  locate -r 'emacs.*\.desktop'
-#  xdg-mime default emacs.desktop text/plain
-#
-if [[  ! -z "`which xdg-open`" ]]; then alias open='xdg-open '; fi
-
-# Let somebody know we finished running
-
-touch $HOME/.bashrc-ran
-debug ".bashrc done"
+   BIN_LS=/bin/ls
+   alias ls='	ls '$color' -a'
+
+
+   # Long List Reverse Tail
+   function llrt() { ls -lrt $color ${*:-}; }
+
+   # Long List Time
+   function llt() { ls -lt $color ${*:-}; }
+
+   # Long List Time, More
+   function lltm() { ls -lt $color ${*:-} | more; }
+
+   # Long List Time, Less
+   function lltl() { ls -alt $color ${*:-} | more; }
+
+   # Long List Time, Head
+   function llth() { ls -lt $color ${*:-} | head; }
+
+   # Long List Time, Tail
+   function lltt() { ls -alt $color ${*:-} | tail; }
+
+
+   # List Sort Size
+   function lss() { ls -a1s $color ${*:-} | sort -n; }
+
+   # List Sort Size Reverse
+   function lssr() { ls -a1s $color ${*:-} | sort -nr; }
+
+   function nf ()
+   {
+       # list the newest file in the current directory
+       NF=`find ${1:-.} -maxdepth 1 -type f -print0 | xargs -0 ls -1t  |  head -1;`;
+       echo ${NF:-/dev/null} | sed "s/ /\\\ /g"
+   }
+
+
+   # new file tail file
+   function nftf { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs tail -f  ; }
+
+   # new file tail
+   function nft { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs tail  ; }
+
+   # new file head
+   function nfh { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs head  ; }
+
+   # new file less
+   function nfl { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs less  ; }
+
+   # new file cat
+   function nfc { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs cat  ; }
+
+   # new file ls
+   function nfls { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs ls -A1t  ; }
+
+   # new file ls -l
+   function nflsl { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs
+   ls -Atl  ; }
+
+   if [[  ! -z "`which xdg-open`" ]]; then alias open='xdg-open '; fi
+
+   touch $HOME/.bashrc-ran
+   debug ".bashrc done"

+ 17 - 17
.bashrc.org

@@ -1,5 +1,5 @@
 #+title: .bashrc
-#+date: <2020-11-29 10:51:24 Sunday>
+#+date: <2020-11-29 12:47:37 Sunday>
 #+author: George M Jones
 #+email: gmj@pobox.com
 #+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:nil arch:headline
@@ -58,7 +58,7 @@
    I define a few syslog-ish helper functions to print warnings,
    errors, etc.
 
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
   #PROG=`basename "$0" | tr -d '\n'`  # normal setting
   PROG="bashrc" # setting for bashrc due to errors
 
@@ -74,7 +74,7 @@
    Here I set a reasonable default prompt that includes timestamp,
    username, host and current directory:
 
- #+begin_src shell :tangle .bashrc.sh :noweb no-export
+ #+begin_src shell :tangle .bashrc :noweb no-export
 export PS1="\# [\t] \u@\h \W/ $ "
  #+end_src
 
@@ -82,7 +82,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
 
    Define various aliases that I use
 
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
   alias rm='	rm -i'
   alias ag='	alias | grep -i'
   alias eg='	printenv | grep -i'
@@ -107,7 +107,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
    one per line.
 
 
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
   function dirl() {
       # "DIR"ectory "L"ist directory stack, one per line
       # Usage: dirl
@@ -141,7 +141,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
 
 ** Misc functions
 
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
 
   function gf() {
   # grep-find: grep for patterins in files via find
@@ -191,7 +191,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
  #+end_src
 
 ** Bash history functions and settings
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
 
   # Preserve history across sesssions
   #
@@ -223,7 +223,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
 ** Set the hostnane, timezone and local
    Set HOSTNAME if ~/etc/hostname exists
 
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
    if [ -e ${HOME}/etc/hostname ]; then
        export HOSTNAME=`cat ${HOME}/etc/hostname`
    elif [ -e /etc/hostname ]; then
@@ -259,7 +259,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
    ssh-add ~/.ssh/id_*
    #+end_example
 
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
    if [ -e ~/bin/sshagent ]; then
        source ~/bin/sshagent
    fi
@@ -267,7 +267,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
 
 ** Copy stdin to clipboard
 
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
    if [[ "$OSTYPE" == "linux-gnu"* ]]; then
      alias 2clip='xclip -selection c'
      alias 3clip='printf %s "$(cat /dev/stdin)" | xclip -selection c'  # no final \n
@@ -282,7 +282,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
   They allow you to place a path first or last in the order (e.g.
   so that ~/bin comes before /usr/local/bin)
 
-  #+begin_src shell :tangle .bashrc.sh :noweb no-export
+  #+begin_src shell :tangle .bashrc :noweb no-export
   pathrm() {
       # remove an item from the path
       if [ -d "$1" ]; then
@@ -331,7 +331,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
    only get used on certian systems or in certian contexts (git, go,
    mail, blog..)
 
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
 
    if [ -d ${HOME}/rc.local ]; then
        for rcfile in $(find ${HOME}/rc.local -name \*.sh); do
@@ -342,7 +342,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
    #+end_src
 
 ** Invoking emacs
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
    alias emacs='setsid emacs'
 
    # from http://stuff-things.net/2014/12/16/working-with-emacsclient/
@@ -359,7 +359,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
    #+end_src
 
 ** ls aliases
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
 
    # coloring for ls functions
 
@@ -401,7 +401,7 @@ export PS1="\# [\t] \u@\h \W/ $ "
    #+end_src
 
 ** Aliases for viewing the newest file in a directoy
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
 
    function nf ()
    {
@@ -443,12 +443,12 @@ export PS1="\# [\t] \u@\h \W/ $ "
    locate -r 'emacs.*\.desktop'
    xdg-mime default emacs.desktop text/plain
 
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
    if [[  ! -z "`which xdg-open`" ]]; then alias open='xdg-open '; fi
    #+end_src
 
 ** All done
-   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+   #+begin_src shell :tangle .bashrc :noweb no-export
    touch $HOME/.bashrc-ran
    debug ".bashrc done"
    #+end_src

+ 454 - 0
.bashrc.pre-org

@@ -0,0 +1,454 @@
+# #+title: .bashrc
+# #+date: <2020-11-29 10:51:24 Sunday>
+# #+author: George M Jones
+# #+email: gmj@pobox.com
+# #+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:nil arch:headline
+# #+options: author:t broken-links:nil c:nil creator:nil
+# #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:2
+# #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t
+# #+options: timestamp:t title:t toc:t todo:t |:t
+# #+language: en
+# #+select_tags: export
+# #+exclude_tags: noexport
+# #+creator: Emacs 28.0.50 (Org mode 9.4)
+# 
+# 
+# * About
+# ** Intro
+#    This is George Jones' .bashrc file as an literate programming file in
+#    emacs org mode using babel blocks.
+# 
+# ** To generate the actual .bashrc
+#    This .bashrc.org file must be process to generate the actual .bashrc
+# 
+#    It can be processed interactively to generate .bashrc via
+#    org-babel-tangle-file or from the command line as
+# 
+#    #+begin_example
+#   emacs --batch --eval "(require 'org)" --eval '(org-babel-tangle-file ".bashrc.org")'
+#    #+end_example
+# 
+#    Permanent changes must be made to the .org version, as the actual
+#    .bashrc will be overwritten when the .org version is "compiled"
+# 
+# ** Debugging
+# 
+#   In most bash files I do
+# 
+#   #+begin_example
+#   set -e
+#   set -u
+#   #+end_example
+# 
+#   but there are problems setting it in .bashrc.   An error then causes
+#   you to exit the shell entirely (not what you want), and there are
+#   several constructs that cause warnings due to undefined variables
+#   (these can/probably should be fixd)
+# 
+#   Set
+# 
+#   #+begin_example
+#   export DEBUG=1
+#   #+end_example
+# 
+#   to enable debugging output from the debug helper function.
+# 
+# * .bashrc
+# ** Helper functions
+#    I define a few syslog-ish helper functions to print warnings,
+#    errors, etc.
+# 
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#   #PROG=`basename "$0" | tr -d '\n'`  # normal setting
+#   PROG="bashrc" # setting for bashrc due to errors
+# 
+#   function info()  { echo ${PROG}\: info: "$@" 1>&2; }
+#   function warn()  { echo ${PROG}\: warning: "$@" 1>&2; }
+#   function error() { echo ${PROG}\: error: "$@" 1>&2; }
+#   function debug() { [[ -v DEBUG ]] && echo ${PROG}\: debug: "$@" 1>&2 || true ; }
+#   function die()   { echo ${PROG}\: fatal: "$@" 1>&2 && exit 1; }
+#    #+end_src
+# 
+# ** Set a reasonable default prompt
+# 
+#    Here I set a reasonable default prompt that includes timestamp,
+#    username, host and current directory:
+# 
+#  #+begin_src shell :tangle .bashrc.sh :noweb no-export
+# export PS1="\# [\t] \u@\h \W/ $ "
+#  #+end_src
+# 
+# ** Misc aliases
+# 
+#    Define various aliases that I use
+# 
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#   alias rm='	rm -i'
+#   alias ag='	alias | grep -i'
+#   alias eg='	printenv | grep -i'
+#   alias hg='	history | grep -i'
+#   alias ht='	history | tail'
+#   alias fpg='	find . -print | egrep -i'
+#   alias egi='	egrep -i'
+#   alias psg='	/bin/ps -auxww | grep'
+#   alias p8='	ping -c 3 8.8.8.8' # make sure routing works
+#   alias pp='	ping -c 3 port111.com' # make sure dns and routing work
+#   alias locate='locate -r'
+#    #+end_src
+# 
+# ** cd commands that use/print the directory stack
+# 
+#    These aliases support pushd/popd/dirs like functionality while
+#    listing one directory per line
+# 
+#    I like to keep a "stack" of directories so I can work on one thing
+#    then "pop" back to where I was.   =pushd= an =popd= support this,
+#    and =dirs= lists the directories, but I prefer to have them listed
+#    one per line.
+# 
+# 
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#   function dirl() {
+#       # "DIR"ectory "L"ist directory stack, one per line
+#       # Usage: dirl
+# 
+#       for d in `dirs`; do echo $d; done
+#   }
+# 
+#   function dirc() {
+#       # "DIR"ectory "C"onnect - connect to directory and list stack
+#       # Usage: dirc [DIR
+# 
+#       pushd ${1:-"$HOME"} > /dev/null
+#       dirl
+#   }
+# 
+#   function dirp () {
+#       # "DIR"ectory "P"op - pop N entries off the directory stack
+#       # Usage: dirp [N]
+#       #
+#       # OLD:
+#       #   alias  dirp='popd > /dev/null && dirl'
+#       for i in `seq ${1:-"1"}`; do
+#           debug "dirl: popd. i is $i"
+#           popd > /dev/null;
+#       done
+#       dirl
+#   }
+# 
+#   alias cd=pushd
+#    #+end_src
+# 
+# ** Misc functions
+# 
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+# 
+#   function gf() {
+#   # grep-find: grep for patterins in files via find
+#   #
+#   # Usage: gf patterns [files [days]]
+#   #
+#   # Examples:
+#   #   gf findMeAnywhere
+#   #   gf findMeInTextFiles '*.txt'
+#   #   gf findMeInTextFiles .txt
+#   #   gf BEGIN\|END .org 30
+# 
+#   local files=""
+#   local days="365"
+# 
+#   set -o noglob
+# 
+#   # First arg is pattern(s) for egrep
+#   if [ -z ${1+x} ]; then
+#     echo 'gf needs string(s) to search for ' 1>&2
+#     info "Usage: gf patterns [files [days]]"
+#     return 1
+#   fi
+# 
+#   # Second arg (if present) is files for find.  No globbing, so "*.txt" OK
+#   if [ ! -z ${2+x} ]; then
+#     if [[ "$2" =~ ^\. ]]; then
+#       # Special case: treat ".foo" as "*.foo"
+#       # Avoids needing to quote on command line
+#       files="-name *$2"
+#     else
+#       files="-name ${2}"
+#     fi
+#   fi
+# 
+#   # $3 (if present) is find -mtime arg, default 365
+#   if [ ! -z ${3+x} ]; then
+#     days="${3}"
+#   fi
+# 
+#   # set -x
+#   find . -type f -mtime -${days} $files -exec egrep --color -H -i "${1}" \{\} \;
+#   # set +x
+# 
+#   set +o noglob
+#   }
+#  #+end_src
+# 
+# ** Bash history functions and settings
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+# 
+#   # Preserve history across sesssions
+#   #
+#   # http://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows
+#   #
+#   export HISTCONTROL=ignoredups:erasedups  # no duplicate entries
+#   export HISTSIZE=100000                   # big big history
+#   export HISTFILESIZE=100000               # big big history
+#   shopt -s histappend                      # append to history, don't overwrite it
+# 
+#   # Save and reload the history after each command finishes
+#   export PROMPT_COMMAND="history -a; history -c; history -r;"
+# 
+# 
+#   function hgt() {
+#       # hgt == "history grep (for arg) tail"
+#       #echo "Histroy Grep tail"
+# 
+#       if [ -z ${1+x} ]; then
+#           echo 'hgt needs an argument' 1>&2
+#           return 1
+#       fi
+# 
+#       history | grep -i "$1" | tail
+#       return 0
+#   }
+#    #+end_src
+# 
+# ** Set the hostnane, timezone and local
+#    Set HOSTNAME if ~/etc/hostname exists
+# 
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#    if [ -e ${HOME}/etc/hostname ]; then
+#        export HOSTNAME=`cat ${HOME}/etc/hostname`
+#    elif [ -e /etc/hostname ]; then
+#        export HOSTNAME=`cat /etc/hostname`
+#    else
+#        export HOSTNAME="unknown"
+#    fi
+# 
+#    # Set timezone if ~/bin/tz.sh exists
+# 
+#    # NEW, if neeeed?
+#    #
+#    # https://linuxize.com/post/how-to-set-or-change-timezone-in-linux/
+#    #
+#    # OLD:
+#    #
+#    # if [ -e ~/bin/tz.sh ]; then
+#    #     echo Setting timezone.
+#    #     source ~/bin/tz.sh # should be in ~/rc.local
+#    # fi
+# 
+#    # STILL NEEDED?
+#    #
+#    # Set local for numeric output
+#    LOCAL=`locale -a | grep -i en_us | head -1`
+#    if [[ "$LOCAL" != "" ]]; then export LC_NUMERIC="$LOCAL"; fi
+#    #+end_src
+# 
+# ** Set up ssh agent
+#    Add keys by hand if needed via
+# 
+#    #+begin_example
+#    ssh-add ~/.ssh/id_*
+#    #+end_example
+# 
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#    if [ -e ~/bin/sshagent ]; then
+#        source ~/bin/sshagent
+#    fi
+#    #+end_src
+# 
+# ** Copy stdin to clipboard
+# 
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#    if [[ "$OSTYPE" == "linux-gnu"* ]]; then
+#      alias 2clip='xclip -selection c'
+#      alias 3clip='printf %s "$(cat /dev/stdin)" | xclip -selection c'  # no final \n
+#    elif [[ "$OSTYPE" == "darwin"* ]]; then
+#      alias 2clip='pbcopy'
+#    fi
+#    #+end_src
+# 
+# ** Path functions
+#   These path* functions add and remove elements to PATH.
+#   They insure that entries are unique.
+#   They allow you to place a path first or last in the order (e.g.
+#   so that ~/bin comes before /usr/local/bin)
+# 
+#   #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#   pathrm() {
+#       # remove an item from the path
+#       if [ -d "$1" ]; then
+#           removeThis="`echo $1 | sed -e 's#/#\\\/#'g`"
+#           newPath=`echo $PATH | awk -v RS=: -v ORS=: "/$removeThis/ {next} {print}" | sed 's/[ :]*$//g'`
+#           export PATH=$newPath
+#       fi
+#   }
+# 
+# 
+#   pathlast() {
+#       # add path to the end if not there
+#       if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
+#           export PATH="${PATH:+"$PATH:"}$1"
+#       fi
+#   }
+# 
+# 
+#   pathfirst() {
+#       # add path to the front if not there
+#       if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
+#           export PATH="$1:${PATH}"
+#       fi
+#   }
+# 
+#   path() {
+#     # show path
+#     echo $PATH
+#   }
+# 
+#   # show path, one entry per line
+#   alias pathcat="echo $PATH | sed 's/:/\n/g'"
+# 
+# 
+#   # Be sure we have a few specific paths if they exist
+# 
+#   pathlast $HOME/bin
+#   pathlast /usr/local/bin
+#   pathlast /opt/bin
+#   #+end_src
+# 
+# ** source ~/rc.local/*.sh to do non-general bash setup
+#    Execute any .sh files in ~/rc.local/*.sh
+# 
+#    This allows me to split out setup for aliases and commands that
+#    only get used on certian systems or in certian contexts (git, go,
+#    mail, blog..)
+# 
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+# 
+#    if [ -d ${HOME}/rc.local ]; then
+#        for rcfile in $(find ${HOME}/rc.local -name \*.sh); do
+#            debug running localrc ${rcfile}
+#            source ${rcfile}
+#        done
+#    fi
+#    #+end_src
+# 
+# ** Invoking emacs
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#    alias emacs='setsid emacs'
+# 
+#    # from http://stuff-things.net/2014/12/16/working-with-emacsclient/
+# 
+#    if [ -z "$SSH_CONNECTION" ]; then
+#        export EMACSCLIENT=emacsclient
+#        alias ec="$EMACSCLIENT -c -n"
+#        export EDITOR="$EMACSCLIENT -c"
+#        export ALTERNATE_EDITOR=""
+#    else
+#        export EDITOR=$(type -P emacs || type -P ed)
+#    fi
+#    export VISUAL=$EDITOR
+#    #+end_src
+# 
+# ** ls aliases
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+# 
+#    # coloring for ls functions
+# 
+#    if [[ "$OSTYPE" == "linux-gnu" ]]; then
+#        color="--color";
+#    else
+#        color=""
+#    fi
+# 
+#    BIN_LS=/bin/ls
+#    alias ls='	ls '$color' -a'
+# 
+# 
+#    # Long List Reverse Tail
+#    function llrt() { ls -lrt $color ${*:-}; }
+# 
+#    # Long List Time
+#    function llt() { ls -lt $color ${*:-}; }
+# 
+#    # Long List Time, More
+#    function lltm() { ls -lt $color ${*:-} | more; }
+# 
+#    # Long List Time, Less
+#    function lltl() { ls -alt $color ${*:-} | more; }
+# 
+#    # Long List Time, Head
+#    function llth() { ls -lt $color ${*:-} | head; }
+# 
+#    # Long List Time, Tail
+#    function lltt() { ls -alt $color ${*:-} | tail; }
+# 
+# 
+#    # List Sort Size
+#    function lss() { ls -a1s $color ${*:-} | sort -n; }
+# 
+#    # List Sort Size Reverse
+#    function lssr() { ls -a1s $color ${*:-} | sort -nr; }
+# 
+#    #+end_src
+# 
+# ** Aliases for viewing the newest file in a directoy
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+# 
+#    function nf ()
+#    {
+#        # list the newest file in the current directory
+#        NF=`find ${1:-.} -maxdepth 1 -type f -print0 | xargs -0 ls -1t  |  head -1;`;
+#        echo ${NF:-/dev/null} | sed "s/ /\\\ /g"
+#    }
+# 
+# 
+#    # new file tail file
+#    function nftf { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs tail -f  ; }
+# 
+#    # new file tail
+#    function nft { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs tail  ; }
+# 
+#    # new file head
+#    function nfh { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs head  ; }
+# 
+#    # new file less
+#    function nfl { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs less  ; }
+# 
+#    # new file cat
+#    function nfc { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs cat  ; }
+# 
+#    # new file ls
+#    function nfls { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs ls -A1t  ; }
+# 
+#    # new file ls -l
+#    function nflsl { NF=`nf ${1:-.}`; debug NF $NF;  echo "$NF" | xargs
+#    ls -Atl  ; }
+#    #+end_src
+# 
+# ** viewing files
+#    Notes on setting up file/mime type assiciatons
+#    https://unix.stackexchange.com/questions/77136/xdg-open-default-applications-behavior
+# 
+#    So...
+# 
+#    locate -r 'emacs.*\.desktop'
+#    xdg-mime default emacs.desktop text/plain
+# 
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#    if [[  ! -z "`which xdg-open`" ]]; then alias open='xdg-open '; fi
+#    #+end_src
+# 
+# ** All done
+#    #+begin_src shell :tangle .bashrc.sh :noweb no-export
+#    touch $HOME/.bashrc-ran
+#    debug ".bashrc done"
+#    #+end_src