indifferent source code access
Much of my .profile, as I'm sure is similar for the .profile of others, is built upon shortcuts and helpers for those commands which get typed (figuratively) millions of times a day.
Given how many repositories I am constantly juggling, I tend to constantly switch between directories containing source code. Early on in my Linux days I began keeping all in-progress projects in ~/src so it turned out to be quite simple to remove a (literally) handful of frequently-typed characters from my continuous workflows.
function csrc {
if [ -d "${HOME}/src/${1}" ] ; then
cd "${HOME}/src/${1}"
else
echo "directory ${1} not found"
fi
}
And then yesterday I was looking for an excuse to figure out how to implement custom bash completion routines and this resulted.
function csrc_complete {
local cur
COMPREPLY=()
if [ $COMP_CWORD != 1 ] ; then
return
fi
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(for d in $HOME/src/$cur* ; do basename $d ; done) )
if [ "${COMPREPLY[0]}" == "${cur}*" ] ; then
COMPREPLY=()
return
else
return 0
fi
}
complete -F csrc_complete csrc
Both of these snippets are nestled on some of the upper layers of my current .profile.
Written by Jonathan Freedman
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#