_                _   _                 ____            _     _  
   / \   _ __   ___ | |_| |__   ___ _ __  |  _ \ _ __ ___ (_) __| |  
  / _ \ | '_ \ / _ \| __| '_ \ / _ \ '__| | | | | '__/ _ \| |/ _` |  
 / ___ \| | | | (_) | |_| | | |  __/ |    | |_| | | | (_) | | (_| |  
/_/   \_\_| |_|\___/ \__|_| |_|\___|_|    |____/|_|  \___/|_|\____| 
                                                                bbs
  XQTRs lair...
Home // 
Blog // 
NULL emag. //  
Files //  
Docs // 
Tutors // 
GitHub repo
CD command on steroids!
Posted on: 2024-07-01, by xqtr
 bash, linux, cd, script
I have seen a similar implementation of a CD command for 
bash/linux that used a method to store a kind of DIR bookmarks 
and i really liked it. For a while i used it, but because it was 
two seperate aliases and very simple i decided to make my own.
So this is my implementation of an alternative CD command, that 
can store directory bookmarks, with aliases and even use it as 
the normal CD command. The cool thing with this implementation is 
the use of aliases/names for the stored directory bookmarks and 
that it has multiple levels of usage... lets explain.
At first, you can use it as the simple cd command. Just give the 
name of the script with a directory location and you will go into 
that dir.
When you are inside a directory that you want to store/add a 
bookmark, just give the name of the command ex. cdb like this:
cdb -s 
All bookmarks are stored in your home directory inside the 
.dirbk.csv file. You can alter this, from inside the script, if 
you want.
To change to a stored directory just give the command with the 
name of the bookmark you gave before. ex: cdb vids
If you mistyped the alias/name of the bookmark and the script 
didn't find a valid directory, it will use FZF to display all 
stored bookmarks and chose from a list! Neat ha?... 
You can edit or view the bookmark file just with a parameter in 
the command, so you don't have to remember the location of the 
file. Just give: cdb -l to view the file or cdb -e to edit it, 
with NANO. You can also see the location of the file with this 
syntax: cdb -f
It's nothing too complicate but i think that is very useful. I 
prefer to add a specific character in front of my aliases, just 
to be sure that i am accessing a bookmarked dir and not an actual 
dir with the same name. For example to store my Videos dir. i use 
an alias like xvideos. In this case there is not a chance to 
navigate to a directory named Videos, perhaps in another place of 
my hard drive, but the specified one in the bookmark.
To get the script, visit the Files area in the website and get 
the file named "cdb". Copy the script inside a folder that is in 
your PATH enviroment variable and make sure to make it 
executable. As a last step, create a Linux alias command like 
this, which i prefer to use:
alias c=". cdb"
So, when i want to use it i type something like this:
c -s name
Make sure to open the script and read the instructions.