Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Sorry, I was mistaken. I confirm that that works too. I was just comparing with wdired.. wdired (Emacs) creates that foo/ dir if it doesn't exist.


sort by: page size:

directory-local variables in emacs? thank you! I will look at that.

Okay I think this is more elegant than my workaround. But it doesn’t work for directories, does it?

That's just an illustration, not 'ideal' code. Of course mkdir -p serves the same purpose; the point is to show the 'file_exists' function.

Mostly it's where using the shell would be painful. Do you have other specific examples?


I have a function for it which is quite useful: mcd () { mkdir "$@" cd "$@" }

Just run mcd foobar and you (try) to create the directory and enter it. IMO a nice shortcut.


I've been looking for something like <() for a long time. Thanks for sharing it!

Regarding :h, is it any different than just using dirname?


Thanks! I didn't realize you could pass in a non-existent directory, that makes it an easier trick.

That doesn't actually create real directories; it's just symbolic links. For certain use cases (nix) this isn't enough.

Yep, and wdired does a few more things as well. From its commentary:

- To move files to another directory (by typing their path, absolute or relative, as a part of the new filename).

- To change the target of symbolic links.

- To change the permission bits of the filenames (in systems with a working unix-alike `dired-chmod-program'). [...]

- To mark files for deletion, by deleting their whole filename.


Thankfully it works in Powershell on Windows. I lost any muscle memory for `dir` a long long time ago.

It works for me if the directory exists.

That's its behaviour in an empty directory, but it works for me on a non-empty directory.

Even worse, there was (and still is) no requirement for a command and its switches to be separated with whitespace.

"DIR/W" is the same as "DIR /W".

Which would have made it impossible to determine whether you want to invoke the command "DIR" in the current directory, or the command "W" in a subdirectory named "DIR".


You almost never need to use "*". Use ".", or go up a dir and type the name of the dir.

Except that only works for absolute paths. And then also changes other semantics that you might expect to be there - e.g. it disables handling of .. and . to mean parent and current directory (which is valid even in absolute paths, and often useful).

I didn't know this one, and glad I do now! Is it possible that the other one I wish existed is already commonplace? I'd like to have an arg that cd's to a directory automatically after mkdir'ing it... or mv'ing a file to a directory.

Something like:

mkdir foo -go and mv foo ~/bar -go

... Probably simple enough to script, but I guess I'm too lazy at the moment.


Not an actual bug, but I found this a couple of days ago. And it seems like an elegant hack, allowing `/` in directory, files, etc.

Typing `mkdir foo:bar` in my macOS's terminal leads to a directory, that Finder shows as `foo/bar`.


Depends on what you're doing. `dir relative/path` does not work.

It depends, could be either, often depends on flags.

For example, mkdir dir (error if it exists) / mkdir -p dir (no error if it exists).

The latter style allows for creating idempotent scripts, which can be nice.


What is the dir/... syntax. I never saw the doc on that one.
next

Legal | privacy