Sha256: 3b1c1c8bb2a2b6d7745b61bc7f3ab924a2b84909b7edbfee93d6a2142530a8cf

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# want to override `cd` so that it will try and change to a local github repo
# iff regular `cd` fails...

function alias_function {
    local ORIG_FUNC=$(declare -f $1)
    local NEWNAME_FUNC="$2${ORIG_FUNC#$1}"
    eval "$NEWNAME_FUNC"
}

function is_function {
  local TYPE=$(type "$1")
  if [[ "$TYPE" =~ "is a function" ]]; then
    return 0
  else
    return 1
  fi
}

is_function "cd"
if [ $? -ne 0 ]; then
  alias_function "cd" "old_cd"
else
  function old_cd {
    builtin cd "$@"
  }
fi

function cd {
  # first, try to execute the `cd`
  old_cd "$@"
  local RTN="$?"
  if [[ $RTN != 0 ]]; then
    echo "looking for a project..." 1>&2
    if rash call 'Project.resolve_repo' "$1"; then
      old_cd `rash call 'Project.dir' $1`
      return $?
    fi
  fi
  return $RTN
  # echo "cd'ing into '$1'"
  # # see if it looks like `$1` will be a directory we can change to from
  # # here, which takes precendence
  # if [ ! -d $1 ]; then
  #   # it doesn't look like it's a dir, so try to 
  #   rash call 'Project.cd' "$1" --RASH_PRINT_ERRORS=0
  #   if [ $? -ne 0 ]; then
  #   echo "using old_cd"
  #   old_cd "$1"
  # else
  #   echo "using Project.cd"
  #   Project.cd "$1" 
  # fi
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nrser-rash-0.2.3 dev/scratch/overridding-cd.sh
nrser-rash-0.2.2 dev/scratch/overridding-cd.sh
nrser-rash-0.2.1 dev/scratch/overridding-cd.sh
nrser-rash-0.2.0 dev/scratch/overridding-cd.sh