Yeah, I couldn't make that work for me (on Linux or MacOS) .. although I'd love it if there were a way to quickly get 'just the directory' or 'just the filename' in bash with a shortcut, instead of having to resort to $(dirname blah) and so on .. I'm sure there is some way but :h doesn't look to be the shortcut as expected.
Except when you pass `-r` and you pass a directory in place of the filename. But maybe it should have been `-r <directory>` and still no positional file parameter. The ship has been sailed a long ago though.
I just wanted the directories, not the files. Your command is great if you want it down to the file level. The -h args are of course a matter of preference.
And with CDABLE_VARS set, you can simply do: dir_name
In fact, you don't even have to use the directory hash for this, you just do, e.g.: MY_DIR=/path/to/dir; MY_DIR
Frankly, this is far superior to the linked method.
Weird that it doesn't seem to support basename (1) and dirname (1) and their Windows equivalents (e.g. %~dp0%)
Quite a few of my scripts need to find files relative to the location of the script, or compute the path to an output file by replacing the extension of an input file.
>However, for root components of a directory, use index.jsx as the filename and use the directory name as the component name
I used to do this, but I find it really confusing having dozens of files all called "index.jsx". I eventually moved to './ComponentName/ComponentName.jsx' in my personal projects. It's a bit more verbose, but I find it makes everything else do to with navigating and finding files easier.
Regarding :h, is it any different than just using dirname?
reply