Explorar el Código

Cleaning up checks for undefined variables

George Jones hace 1 año
padre
commit
7179a76488
Se han modificado 3 ficheros con 18 adiciones y 324 borrados
  1. 18 8
      .bashrc
  2. 0 154
      rc.local/find-aliases.sh
  3. 0 162
      rc.local/latest.sh

+ 18 - 8
.bashrc

@@ -27,8 +27,14 @@ function set_xtitle {
     # Usage:
     #
     #   set_xtitle [name]
+
     WINDOW_NAME="${1:-`basename $PWD`}"
-    PROMPT_COMMAND="echo -ne \"\033]0;${WINDOW_NAME} $USER@$HOSTNAME:$PWD\007\"";
+
+    if [[ -v INSIDE_EMACS ]]; then
+        PROMPT_COMMAND="echo -ne ${WINDOW_NAME} $USER@$HOSTNAME:$PWD";
+    else
+        PROMPT_COMMAND="echo -ne \"\033]0;${WINDOW_NAME} $USER@$HOSTNAME:$PWD\007\"";
+    fi
 }
 export PS1="\# [\t] \u@\h \W/ $ "
 
@@ -172,11 +178,14 @@ shopt -s histappend                      # append to history, don't overwrite it
 
 # Save and reload the history after each command finishes
 
-if [[ -z "${DISPLAY}" ]]; then
-    export PROMPT_COMMAND="history -a; history -c; history -r;echo -ne \"\033]0;$USER@$HOSTNAME:$PWD\007\""
-else
+if [[ -v INSIDE_EMACS ]]; then
+    # no escape characters
+    export PROMPT_COMMAND="history -a; history -c; history -r;echo -ne \`whoami\`@\`hostname -s\`:"
+elif [[ -v DISPLAY ]]; then
     # in X-land, set window title to user@host:pwd
     export PROMPT_COMMAND="history -a; history -c; history -r;echo -ne \"\033]0;\`whoami\`@\`hostname -s\`:\`pwd\`\007\""
+else
+    export PROMPT_COMMAND="history -a; history -c; history -r;echo -ne \"\033]0;$USER@$HOSTNAME:$PWD\007\""
 fi
 
 # modern GPG setup
@@ -314,14 +323,15 @@ alias emacs='setsid emacs'
 
 # from http://stuff-things.net/2014/12/16/working-with-emacsclient/
 
-if [ -z "$SSH_CONNECTION" ]; then
+if [[ -v SSH_CONNECTION ]]; then
+    alias ec="emacsclient -c"
+    export EDITOR=$(type -P emacs || type -P ed)
+
+else
     export EMACSCLIENT=emacsclient
     alias ec="$EMACSCLIENT -c -n"
     export EDITOR="$EMACSCLIENT -c"
     export ALTERNATE_EDITOR=""
-else
-    alias ec="emacsclient -c"
-    export EDITOR=$(type -P emacs || type -P ed)
 fi
 export VISUAL=$EDITOR
 

+ 0 - 154
rc.local/find-aliases.sh

@@ -1,154 +0,0 @@
-# Aliases and functions to find files that have chagened
-#
-# This is an evolvoing collection of aliases and fucntions
-# to find files that have changed from the command line.
-#
-# There may be some overlap.
-
-
-
-function latest (
-    # Find lastest modified files and grep them.
-    #
-    # define parameters that control find(1)
-
-    WHAT=${1:-.}
-    AGE=${AGE:-7}
-    WHERE=${WHERE:-.}
-    # define filenames/paths to be ignored
-    #define junk files.  Your junk milage may vary.
-
-    prune_linux='foo/|git/|backups/|auto-save-list|config/|snap/|cache/|local/|mozilla/|target/|.rustup/|.cargo/'
-    prune_just_me='blog/docs'
-    prune=".*(${prune_just_me}|${prune_linux}).*"
-    # define errors to be ignored
-
-    # define parameters that control grep of file content
-    GREP=${GREP:-}
-    FLAGS=${FLAGS:-}
-
-    if [[ ${1} == "-h" ]]; then
-        WHAT="."
-        info 'Locate latst files'
-        info "Usage: [WHERE=${WHERE}] [AGE=${AGE}]  latest [WHAT=${WHAT}]"
-        exit 1
-    fi
-
-
-    [[ -v DEBUG ]] && set -x
-    if [ "${GREP}" == "" ]; then
-        # basic find functionality
-
-#        find . -regextype posix-extended -regex '.*(foo|r).*' -prune -o -print
-
-        # -xdev \
-
-        debug "prune is ${prune}"
-
-        find -L ${WHERE} \
-             `: global options` \
-             `: prune 'junk' files and dirs` \
-             -regextype posix-extended \
-             -xdev \
-             -regex "${prune}" -prune -o \
-             `: only look at regular files ` \
-             -type f \
-             `: restrict to mtime AGE days ago` \
-             -mtime -${AGE}\
-             `: restrict to files that match WHAT in full path` \
-             -regex ".*${WHAT}.*" \
-             -print #\
-            # TODO Add grep options
-            #   - Grep sring on command line
-            #     + only do --exec grep if present
-            #   - option for filenames only on grep -H
-            #   - optoon for case insensitive -i
-            #   - option for invert -v
-            # so probably some syntax like
-            #
-            # latest [locate options] WHAT [grep [grep optons] grep-regex]
-
-        #| grep ${WHAT}
-    else
-        # grep contents of files found
-        error locate does not yet implement grep for content
-    fi
-    [[ -v DEBUG ]] && set +x
-)
-
-# Define some logging aliases
-source ~/lib/bash/bashutils.sh || `: # Use my library if available`\
-    `: fall back to echo`
-    alias info=echo && \
-    alias warn=echo && \
-    alias error=echo
-
-function lorg (
-    # Locate .org files
-    #
-    # This function was written primarily to find .org files in my home directory.
-    #
-    # It used locate(1) to search fro WHAT
-    # It can be used to find files of other types (EXT=) anywhere (WHERE=).
-    # Certian files/patters (files with spaces) can be ignored with EXCLUDE=
-    # Setting DEBUG=1 will print the commands executed (set -x)
-
-    if [[ ${1} == "-h" ]]; then
-        info 'Locate .org files'
-
-        exit 1
-    fi
-
-    # By default, WHAT is everything
-    WHAT=${1:-'*'};
-    # Only include files with this extention
-    EXT=${EXT:-org}
-    # Only include things here (change to WHERE=/ for whole system)
-    WHERE=${WHERE:-$HOME}
-    # grep -E pattern of thigs to exclude (junk files, backups, files with spaces..)
-    EXCLUDE='backup|[[:space:]]'
-
-    [[ -v DEBUG ]] && set -x
-    \locate -i "${WHAT}" | `: # locate files with WHAT in them` \
-     grep -E \\."${EXT}"\$ | `: # Only include things ending in .${EXT} `\
-     grep -E "${WHERE}" | `: # Only include things in these dirs ($HOME,"/"...)`\
-     grep -E -v "$EXCLUDE" `: # exclude patterns form EXCLUDE (backups, spaces...)`
-    [[ -v DEBUG ]] && set +x
-)
-
-function gorg (
-    # grep for WHAT in org (or EXT) files younger than AGE
-    #
-    # Usage:
-    #   [FLAGS=-i] [EXT=.org] [WHERE=$HOME] gorg [-h] [WHAT [AGE]]
-    #
-    # Enviornment Variables:
-    #   WHAT   - regexp to serach for
-    #   WHERE  - WHERE to search.  Default "."
-    #   AGE    - files not older than AGE days.  Default 7.
-    #   EXT    - Search files of this extention.  Default ".org"
-    #   FLAGS  - used for grep flags.  Set to "FLAGS=-i" for case-insensitive, "FLAGS=-l"  for names only
-    #   DEBUG  - set to "1" for debugging
-    #
-    # Example
-    #
-    WHAT=${1:-"DONE"};
-    AGE=${2:-7};
-    WHERE=${WHERE:-$HOME};
-    EXT=${EXT:-"org"}
-
-    if [[ $WHAT == "-h" ]]; then
-        info "Usage: [DEBUG=1] [FLAGS=] [EXT=.org] [WHERE=$HOME] gorg [WHAT [AGE]]"
-        exit 1
-    fi
-
-    COLOR="--color=always"
-
-    if [[ "$FLAGS" != "" ]]; then
-       unset COLOR
-    fi
-
-    [[ -v DEBUG ]] && set -x
-    find "${WHERE}" -xdev -type f -name \*."${EXT}" -mtime -"${AGE}" -exec grep ${COLOR:-} ${FLAGS:-} -H -e    "${WHAT}" \{\} \; |& grep -v "No such file"
-    [[ -v DEBUG ]] && set +x
-)

+ 0 - 162
rc.local/latest.sh

@@ -1,162 +0,0 @@
-function latest (
-    # Find lastest modified files and grep them.
-    #
-    # This is really just a wrapper around find -exec grep,
-    # but it encapsulates some defaults/patterns I use a lot
-    #
-    #   - Looking for recently modified (AGE) files
-    #   - Looking at certain types of files (WHAT, e.g. .org)
-    #   - Looking in the current directory (WHERE) usually
-    #   - Grep(1)ing for file content (GREP)
-    #     + sometimes case insensitive
-    #     + usually using --color
-    #   - Ignoring junk (PRUNE)
-
-    # Define some logging aliases
-    source ~/lib/bash/bashutils.sh || `: # Use my library if available`\
-    `: fall back to echo`
-    alias info=echo && \
-    alias warn=echo && \
-    alias error=echo
-
-    #
-    # Defaults for parameters that control find(1)
-    #
-    WHAT=${WHAT:-org}
-    AGE=${AGE:-7}
-    WHERE=${WHERE:-.}
-    # define filenames/paths to be ignored
-    #   "junk" stanard on linux systems
-    PRUNE_LINUX='git/|backups/|auto-save-list|config/|snap/|cache/|local/|mozilla/|target/|.rustup/|.cargo/'
-    #   junk specific to me  Your junk milage may vary.
-    PRUNE_JUST_ME='blog/docs'
-    PRUNE=".*(${PRUNE_JUST_ME}|${PRUNE_LINUX}).*"
-    #
-    # defaults for parameters that control grep of file content
-    #
-    GREP=${GREP:-}
-    #
-    # define errors to be ignored
-    #
-    # TODO grep out?
-
-
-    function usage ()  {
-        message=${1:-""}
-        cat <<EOF 1>&2
-Usage: latest [options] [WHERE] [AGE] [[WHAT] REGEX]]
-
-       find the latest files and what's in them.
-
-Options
-  -a|--age=AGE         Max age of files to find.   Default: $AGE
-  -h|--help            print help text
-  -g|--grep=REGEX      Regex to grep in files.     Default: None.
-  -s|--sensitive       Grep is case sensitive.     Default: case insensitive.
-  -w|--where=DIR       Where to search for files.  Default: $WHERE
-
-Arguments
-  First one or two positons.
-    WHERE         A path (incuding "/").  Overrides -w.
-    AGE           Max age.  Digits.  Overrides -a.
-
-  First non-age (digits), non-path (contains "/") argument
-    WHAT		Filenames to search for, in full path.  Default: $WHAT
-
-  Second non-age (digits), non-path (contains "/") argument
-    REGEX         Regex to grep.  Overrrides -g.
-
-Examples:
-  # find latest .org files in current directorry
-    lastest
-
-  # find .sql files modified in the last 30 days in the home directory
-    latest -a 30 -w $HOME sql
-      or
-    latest 30 $HOME sql
-
-  # find python files with "pandas"
-    latest -g pandas .py
-      or
-    latest .py pandas
-
-
-EOF
-
-    }
-
-    # parse optons
-    while [[ $# > 0 ]]; do
-      case ${1} in
-        -a|--age)	shift; AGE="$1"; [[ $# > 0 ]] && shift || die '--age requires an argument';;
-        -d|--debug)	DEBUG=1 && shift;;
-        -g|--grep)	shift; REGEX="${1}" && shift || die '--grep requires an argument';;
-        -h|--help)	usage && return 1;;
-        -w|--where)	shift; WHERE="$1" && shift || die '--where requires an argument';;
-        -*)              error "Unknown flag: $1" && return 1;;
-        *)             break;;
-       esac
-    done
-
-    # parse args
-
-
-    found_what=false
-    found_regex=false
-
-    while [[ $# > 0 ]]; do
-        if [[ "$1" = */* ]]; then
-            WHERE=$1;
-            shift;
-        elif [[ "$1" =~ ^[0-9]+$ ]]; then
-            AGE="$1"
-            shift
-        elif [[ $found_what == true ]]; then
-            REGEX="$1";
-            found_regex=true;
-            shift;
-        else
-            found_what=true;
-            WHAT="$1";
-            shift;
-        fi
-
-        # if [[ $# == 0 ]]; then
-        #     break
-        # fi
-    done
-
-    # if [[ $# = 1 ]]; then
-    #     WHAT="$1"
-    # elif [[ $# = 2 ]]; then
-    #     WHAT="$1"
-    #     REGEX="$2"
-    if [[ $# > 0 ]]; then
-        die "too many arguments given.  At most 3 allowed.  Unknow: ${ARGV[*]}"
-    fi
-
-   [[ -v DEBUG ]] && set -x
-
-   GREPFLAGS=()
-   if [[ -v REGEX ]]; then
-       GREPFLAGS=("-exec" "grep" "--color=always" "-H ""-E"  "$REGEX" '{}' ';')
-   else
-       GREPFLAGS=( '-print' )
-   fi
-
-   find -L ${WHERE} \
-        `: global options` \
-        `: prune 'junk' files and dirs` \
-        -regextype posix-extended \
-        -xdev \
-        -regex "${prune}" -prune -o \
-        `: only look at regular files ` \
-        -type f \
-        `: restrict to mtime AGE days ago` \
-        -mtime -${AGE}\
-        `: restrict to files that match WHAT in full path` \
-        -regex ".*${WHAT}.*" \
-        ${GREPFLAGS[*]}
-
-    [[ -v DEBUG ]] && set +x
-)