4 ms·
Another one: cdof () { cd "$(dirname $1)" } as in 'Change into Directory Of" Changes into the directory of a file. This is useful when you're doing c
by MawKKe 5y ago
Another one:
cdof () {
cd "$(dirname $1)"
}
as in 'Change into Directory Of"
Changes into the directory of a file. This is useful when you're doing complicated commands with long path names, but realize it would be easier if you were to cd into that directory. Use in combination with <Alt+.>. Especially useful if the filename component is long:
$ pwd
=> ~/
$ ls -l path/to/whatever/deep/somewhere/2021-04-22-filewithverylongnamefoobarbaz.xyz
$ cdof <Alt+.>
$ pwd
=> path/to/whatever/deep/somewhere
- w0m 5y agooooh; stealing this nice.
- gjvc 5y agobit longer, but if given a file, change to its directory function cd() { if [[ ${#} -eq 0 ]]; then builtin cd return fi if [[ -f ${1} ]]; then builtin cd $(dirname ${1}) else builtin cd ${1} fi }
- javier10e6 5y agoTried in cygwin and was a no-go. Tried some other concoctions in stack-overflow without success. Then I whiped this one and it worked. With a warning that will be promptly subdue to >/dev/null function gothere { cd $(dirname -z `find -iname $1`) }