Lurker News
I recently started integrating tmux and vim into my workflows. Obviously, it was a huge efficiency booster. What are some other tools (custom built or off-the-shelf), hotkeys, workflows that were game-changing for you as a dev? I'm interested in hearing about anything and everything (stuff from ctrl+l to clear the terminal to little-known git commands to larger-scale strategies like CI/CD)

Comments (522) 158 threads

Show all comments

Showing thread 11 of 158

dceddia7 replies#
A couple others have mentioned shell tricks. One of my favorites is using Alt-. (in Bash and Zsh) to insert the last argument of the previous command. Press it multiple times and it will cycle through the last argument of all previous commands. It's great for when you want to, say, `ls thing` and then `vim thing`.

Yesterday I went looking for a similar key that would insert a copy of the last argument on the current line, like for when you want to copy or rename a file to a similar name in the same directory, as in `cp some/long/path/to/foo.txt some/long/path/to/foo2.txt`.
I couldn't find a command for this, so I made my own Zsh "widget" and bound it to Alt-/ so now I can type `cp some/long/path/to/foo.txt` and hit Alt-/ to prefill the second arg. I put the code for it up here: https://gist.github.com/dceddia/0a45a88dd61cbdf1be023d0a8f15...

cs02rm02 replies#
I think !$ will do similar, at least in bash.

(I'm on a phone and normally rely on muscle memory so it might be the wrong symbols).

edaemon1 reply#
`!$` is right, though it isn't interactive like `Alt+.` is.
mkl2 replies#
Yes it is, you just need to press Alt-^ to do history expansion on it.

Continue this thread — 2 replies

dceddia#
Maybe I misunderstood, or it does something different in zsh, but it seems like it's inserting the command itself:

    ls foo.txt !$

    ls: ls: No such file or directory
    foo.txt
DaanVanVugt1 reply#
For `cp some/long/path/to/foo.txt some/long/path/to/foo2.txt` I always liked brace expansion, for example

`cp some/long/path/to/{foo,foo2}.txt`
(Though foo{,2}.txt is even shorter)

read_if_gay_#
Gonna have to try doing this, I usually cd to the source/target directory in these situations, then copy it and use cd - to get back quickly.
chadlavi2 replies#
I assume you're talking about only on linux? On a mac `alt .` and `alt /` are mapped to characters ≥ and ÷
bandris1 reply#
Esc-. is more portable. Works on mac too.
kanyethegreat#
Yea, this is what I use.
dceddia#
I'm on a Mac using iTerm, but I think I've tweaked some setting about meta keys somewhere in preferences.
kanyethegreat#
Yes, I love this one! I'll check out the widget. Sounds cool! I have the same problem (it's usually changing filenames, so I just use fzf twice, then modify the second filename).

There was one bash feature along the same lines of this. It was like bringing up the previous command in a shell script, so you could modify it freely, then run it. It was useful for long command, I think. Haven't tried learning it though. Just saw a couple wizard colleagues using it, and it seemed cool.

war10252 replies#
One of my favorite bash tricks is that I have this alias in my bashrc file:

   function goto {
      cd -P ~/.links/"$1";
   }

And then in the `.links` folder I have symbolic links to directories I need to go to often.

Then getting to a frequently used directory is just a `goto X` away.

erik_seaberg1 reply#
Cool. How does that compare with setting CDPATH?
war1025#
I just looked up CDPATH and my understanding is that the difference between the two is that with CDPATH you are setting directories that you can quickly navigate to subdirectories of.

This is more of a quick link to directories themselves.
Maybe you could do something similar to the alias if you had my `~/.links` directory in your CDPATH, but then you'd still need to add the `-P`every time to get it to follow the symbolic link.
Not something I had ever thought of before honestly.

bruh2#
Ooh, that's cool. You might be interested at z[1]. It kinda fills the same purpose as your trick, except it automatically figures out what are your most used directories by tracking your shell navigation or something.

[1] https://github.com/rupa/z/wiki

noisy_boy#
$_ will do the same thing in bash as in "ls thing" and then "vim $_" (but only works for arguments from the last command)
mpawelski#
Thanks! I didn't know about Alt-. I'm using powershell and it works there too.