News for hackers. Stuff that matters.
Re:Which command did you run 1731 days ago? by permalac on Sunday January 21, 2024 @04:38AM (#39077021)
Good tool, but my history is so noisy I had to find another way. Lately I started to add a new habit in my shell actions.

When a command has some cognitive requirements I create a script with some ${1:-default} values and I store them all in $PATH enabled local/bin

All my scripts start with __ and then some capital letters indicating the topic.

I can copy them to new machines, which is something I would not do with my history.

Re:Which command did you run 1731 days ago? by caeruleus on Sunday January 21, 2024 @07:44AM (#39077947)
Prefixing these utility scripts is a nice tip, I used to do that as well.

Some time ago I found sd [1] though. It's a light wrapper around your own scripts which provides namespaces, autocompletion, custom help texts + some other QoL enhancements around that. It improves discoverability and usability a lot, very happy with it.

[1]: https://github.com/ianthehenry/sd

Re:Which command did you run 1731 days ago? by thenbe on Sunday January 21, 2024 @05:56AM (#39077379)
> my history is so noisy I had to find another way

The fzf search syntax [1] can help, if you become familiar with it. It is also supported in atuin [2].

[1]: https://github.com/junegunn/fzf#search-syntax

[2]: https://docs.atuin.sh/configuration/config/#fuzzy-search-syn...

Re:Which command did you run 1731 days ago? by Biganon on Sunday January 21, 2024 @06:22AM (#39077495)
I use a similar trick but even dirtier

Whenever I'm satisfied with a pretty long command, I add a comment at the end that explain what it does (#blablabla). Makes searching sort of easier.

Re:Which command did you run 1731 days ago? by bananskalhalk on Sunday January 21, 2024 @04:50AM (#39077079)
Prefixing your scripts is an awesome tips. A colleague told me he prefixed all his commands with ',' and I've started to do the same. '_' might clash with 'hidden'(?) shell expansions etc.

Sadly git doesn't allow for aliases with an comma-prefix, so all git aliases starts with a dot.

Re:Which command did you run 1731 days ago? by gumby on Sunday January 21, 2024 @07:37AM (#39077902)
You can make symlinks or shell aliases that just reference git-add et al directly.
Re:Which command did you run 1731 days ago? by __MatrixMan__ on Sunday January 21, 2024 @05:57AM (#39077383)
Nushell has a SQLite history mode which captures more metadata than is typical. I haven't looked into extending it, but it seems like a good setup for adding enough so that some of these cognitive requirements could be recovered from history rather than thought of up front.

Like if I tend to go down the wrong path, fix it, and then go down the right path, maybe that's a pattern that can be identified and then when I search history it finds two or three commands which together set me on the right path in the first place.

I mean, thinking ahead is always gonna be better, but I don't always.

Re:Which command did you run 1731 days ago? by traviscj on Sunday January 21, 2024 @06:06AM (#39077417)
I’ve done this enough times I chain the desired command and the cd together:

    cd ~/x/y/z && my-command
So that when I CTRL-R for my-command it automatically reminds me.
Re:Which command did you run 1731 days ago? by gumby on Sunday January 21, 2024 @08:02AM (#39078071)
If you’re doing this for history value put it in a subshell so it doesn’t change your working directory in a confusing way:

    (cd ~/x/y/z && my-command)
Re:Which command did you run 1731 days ago? by chrisshroba on Sunday January 21, 2024 @11:14AM (#39079774)
Neat idea, definitely going to use this! Thanks for sharing
Re:Which command did you run 1731 days ago? by __MatrixMan__ on Sunday January 21, 2024 @07:12PM (#39084481)
cwd is one of the default fields. Here's my first nushell command:

    $ history | get 0
    ╭─────────────────┬─────────────────────────────╮
    │ start_timestamp │ 2023-12-15 15:39:12.872 UTC │
    │ command         │ ls                          │
    │ cwd             │ /home/matt/src/configs      │
    │ duration        │ 31 ms                       │
    │ exit_status     │ 0                           │
    ╰─────────────────┴─────────────────────────────╯
It would take some smarts to figure out when to bind the cwd and when not to, but that would be the interesting part.
Re:Which command did you run 1731 days ago? by donaldihunter on Sunday January 21, 2024 @09:35AM (#39078777)
I do a lot of literate coding for shell work, using org-mode. I have param substitution, command chaining, textual explanation and saved output from the last time commands were run. I can save the .org files for reference, or add them directly to my blog.
Re:Which command did you run 1731 days ago? by BeetleB on Sunday January 21, 2024 @01:12PM (#39080973)
> When a command has some cognitive requirements I create a script with some ${1:-default} values and I store them all in $PATH enabled local/bin

I would consider using just for this:

https://github.com/casey/just