I need a simple bash script function for .bashrc file to navigate to my home directory. We use hg for all our work purpose in the directory and contains many streams.
/home/<username>/RelStream1/
/home/<username>/RelStream2/
/home/<username>/RelStream3/
/home/<username>/RelStream4/
For namesake i call this /home//RelStream1/ path as repo home.
Now for work purpose, i need to navigate to sub folders from my repo home path.
/home/<username>/RelStream1/pkgdir/appsdir/moduledir/submoduledir/....
After finishing work, i need to come back to home repo directory for compilation.
I have added alias like this, but still its painful to remember the path back.
alias ..="cd .."
alias ..2="cd ../.."
alias ..3="cd ../../.."
alias ..4="cd ../../../.."
alias ..5="cd ../../../../.."
Please note many repo home directories would be used at any point of time and hence setting aliases as alias rhome='cd /home/<username>/RelStreamX/'
will have little use.
I just need a simple bash function to get back to repo home directory (current repo). It has to get the current path and navigate my directory back to home repo directory
Ex1:
From: /home/<username>/RelStream1/pkgdir/appsdir/moduledir/submoduledir/
To: /home/<username>/RelStream1/
Ex2:
From: /home/<username>/RelStream3/pkgdir/appsdir/moduledir/submoduledir/micromodule/
To: /home/<username>/RelStream3/
Ex3:
From: /home/<username>/RelStream4/pkgdir/appsdir/
To: /home/<username>/RelStream4/
I have tried some methods in bash(beginner), but does not give expected results.
code:
repohome_func()
{
cwd=$(pwd)
echo "CurrPath:${cwd}"
sep="/"
//My plan is to search the cur path with "/" char up to 4 times,
//cut the front string and then execute that cmd.
}alias rhome=repohome_func