Monday, May 25, 2020

Make your Mac folder shortcuts into terminal command

Every day all you geeks are typing 'cd' command more than like any another command.
As you want to navigate to move almost nuke and corner of your file system.
But sometimes you often go to a specific folder, maybe that is Downloads or you specific workspace folder.


~ cd ~/Downloads
➜  Downloads
 
As this is very near to home folder and shot, it is easy to navigate but what if you have a project-specific folder that has a 100 character length path. Alias is useful to set shortcut command for your folders.
Edit your shell source file by doing the following command in terminal
 
vi ~/.zshrc

or
 
vi ~/.bash_profile

Update below content into the bottom of your source file,
 
#Alias to my Download folder 
alias downloads='cd ~/Downloads'

Save the profile file by doing vi save (escape + :wq!)
 
➜  downloads

Now type downloads in your terminal hit enter. You are into the Downloads folder.

Troubleshoot:
 Restart the terminal if not working, or check the typo to your profile settings

Below command can be useful to add the current directory to the alias list, as it avoids to open the
bash_profile to update in the vi editor.

 Replace the <name> with the actual value. after the edit, there should not any angle brackets in the terminal command.


➜  echo "alias <name>='cd $PWD'" | cat >> ~/.bash_profile 

Note: As this is appended command, please make sure that you execute it once per alias name.

No comments:

Post a Comment

Merging two sorted arrays - Big O (n+m) time complexity

 Problem :  Merge the two sorted arrays. Edge case :  Array can empty Arrays can be in different size let getMaxLength = ( input1 , input...