Fast change directory for the cli.
Linux kernel 2.6, GNU (Slackware 12.0).
Hi: In the old days of M$-DOS, there was the NCD (Norton Change Directory) utility. Anything of the sort in Linux? Explanatory note: you typed out the name of the directory you wanted to go to, that is, last element of the dir path. And you were, ipso facto, in that dir. If that was the only one by that name, good. When not, and if that wasn't the intended dir, you typed the same command again and you were in a second dir of that name. If this was the intended dir, good. And so on. It simply maintained a data base with the whole tree, and updated it when invoked from a newly created dir o by means of an option, NCD/R. Regards. |
You could make a script to do that ...
The * can achieve part of the functionality ... Code:
$ cd /*/[directoryname] |
Thanks. I'll get to it. Do you think the algorithm would better be recursive or iterative?
|
Using CDPATH to achieve the NCD functionality
dxqcanada sez:
Quote:
Nice trick! Two comments: 1) You can't do it in a script if by script you mean: Code:
#!/bin/bash It gives your standard cd command more mojo. 2) To your ~/.bashrc file add: Code:
# This little beauty (CDPATH) allows you to type cd postit and go right to in /home/joebob/favdirectory/work/hotprojects. |
Most bash users probably approach this a little different: tab expansion.
To change to favdirectory/work/hotprojects, I would type f<tab>w<tab>h<tab><enter> The tab character fills in the remaining part of the directory for me. But if there are two directories or files that start with f, nothing would happen, so I would press the a and try again, etc. If I forget how it's spelled, I press tab a couple more times until it displays all my choices. |
Unfortunately, I create directories in such a way that 6-element paths and up is normal usage for me. Worsened by my having to begin by the name of the partition as the first element. Also, I'm a lazy typer. The n-c-d key sequence is extremely fast to type and then, thumb over the space bar and just a few chars.
It is because I was tired of pressing the TAB key that I posted these letters. And pcardout's idea could work fine for the most visited paths. But falls short of my idea. I did find a program named ytree on the web. But it's not a hundred per cent cli-ish. Well, thanks for your time. |
I did not mean that that particular command would be the script ...
If there isn't already a tool that can do this ... a script could be written to do it. |
I would think that it would be best to write a small script that had your most visited directories and would try those after the current directory is processed. OR something that searched the output of the find command...
find ${DIRLIST} -type d -name $SEARCH 2> /dev/null then something that selects the directory to cd to. you can modify $SEARCH to '*'${SEARCH}'*' if you wanted to get any directory containing the pattern. I have issues sometimes when bash tries to interpret the * so I quote it. If your DIRLIST is too broad or has too many sub directories, then you will get a lot of directories you probably don't want. So you might want to limit that to a few key places that you are working with a lot. If you want to do it windows style, use "-iname" for a case insensitive search. Hrmmms actually, I think I found nearly the exact command to place in a script with very minimal typing. Code:
#!/bin/bash EDIT YET AGAIN: I think it actually has to be a function that you source to your bash profile so that you remain in the directory after you cd to it... |
For years I've been doing something like what others in this thread have suggested.
In my ~/.bash_profile file I have this line: Code:
alias prj=". ~/bin/prj" Code:
case "$1" in You could extend this in obvious ways. |
You might get similar behaviour to what you want with a combination of CDPATH and the shopt option 'cdspell'. I have some of my $HOME subdirectories in CDPATH and I can just start to type their name then a <TAB> and jump straight to them. shopt -c cdspell tells Bash to correct small spelling errors automatically.
What this won't give you is a second attempt in the event the first suggestion is not the dir you're looking for, but you might find this suggestion is good enough. |
I'll have a lot of fun trying each solution! Thanks.
|
Quote:
The environment variable "CDPATH". Also cd -, cd-3, cd +2, etc |
If this need is to move around within a software project. Look into vim (gvim is the gui enabled version) and the "ctags" program. It allows the move to the definition under the cursor (or from a command) and has return to the previous location (multiple returns).
|
Quote:
|
I'll do it. Thanks.
|
All times are GMT -5. The time now is 12:12 AM. |