Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This bash config allows you to cd directly to the most commonly used directory with a specific name. It also has tab autocomplete. It does require logging all used directories though.

  tabChar=$'\t'
  function prompt_command {
      echo "$(date +%Y-%m-%d--%H-%M-%S)$tabChar$(hostname)$tabChar$PWD$tabChar$(history 1)" >> ~/.full_history
  }
  export PROMPT_COMMAND=prompt_command
  
  function c {
      while read -r _ dir
      do
          if [[ -e "$dir" ]]
          then
              echo "$dir"
              cd "$dir"
              break
          fi
      done < <(cat ~/.full_history | tail -n 10000 \
          | cut -f 3 | sort | uniq -dc | sort -hr | grep "/$1$")
  }
  
  function _c {
      local IFS=$'\n'
      COMPREPLY=( $(cat ~/.full_history | tail -n 10000 \
          | cut -f 3 | sort | uniq -dc | sort -hr \
          | sed 's/.*\///g' | grep "^$2") )
  }
  complete -F _c c



+1 for z. one of the best timesavers available.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: