News for hackers. Stuff that matters.
Re:Using hashtags to organize your bash history by mooism2 on Sunday June 30, 2013 @04:31AM (#5965126)
Or you could stick the command in a shell script.

  #!/bin/sh
  find . -iname '*.php' -print0 | xargs -0 -n1 php -l
Save it to ~/bin/phplint (you do have ~/bin in your PATH, right?), chmod +x it, check it in, and you have a new phplint command. No need to mess about with hashtags in your shell history.

Am I missing something?

Re:Using hashtags to organize your bash history by twic on Sunday June 30, 2013 @10:18AM (#5965853)
What you may be missing is the difference in length between:

  Create a file ~/bin/phplint
  Type out the shebang
  Copy the command from the terminal into the file
  Save the file
  chmod +x the file
And:

  type #phplint
I'm sure Mr Venkat wouldn't claim that he has rendered script directories overnight. But he has come up with a way to make your shell history a little more usable.

I observe that people vary a lot in how hard they lean on their history. I live and die by mine; it serves as a combination of replacement short-term memory and treasury of tricks. Some of my colleagues don't really use it at all, using scripts or aliases, or even just retyping commands every time, like savages. If you're not a heavy user of history, then this idea won't help you. If you are, it might.

Re:Using hashtags to organize your bash history by mooism2 on Sunday June 30, 2013 @02:20PM (#5966626)
You're right, the first alternative is disgustingly long-winded. Let's automate it.

Create a new shell script called `empty` somewhere on your PATH:

  #!/bin/bash
  set -e
  exec >"$1"
  printf '#!'
  which "$2"
  chmod +x "$1"
  cat
Next, add a new shell function to your ~/.bashrc:

  save-history() {
    history -p "$1" | empty ~/bin/"$2" bash
  }
To save the most recent command in your history to a shell script called ~/bin/phplint, run

  save-history '!!' phplint
You have to single-quote the '!!'; sorry about that. I'm using bash; maybe zsh has some way of making this easier to use.

Having said that, if you're happy (I'm speaking generically here, not specifically to twic) relying on your history, then more power to you. It doesn't work for me because I haven't worked out yet how to keep my shell history straight between several shell sessions on the same PC, let alone syncing it between different PCs.

Re:Using hashtags to organize your bash history by jpk on Sunday June 30, 2013 @05:13PM (#5967242)
In the spirit of the OP, I did a similar thing, but using a tag to initiate writing the script file. https://github.com/thatjpk/bashtag-save

So, tagging a command line with "#save:scriptname" will save the command to ~/scripts/saved/scriptname.sh That way you can get the history search token and a script on disk in one fell swoop.

Re:Using hashtags to organize your bash history by ibotty on Sunday June 30, 2013 @05:29AM (#5965225)
no you are not. but some one-offs are good enough to reuse, but not good enough to open an editor for, depend on environment variables (which might be spelled out in the command), or something. so although i do use a pretty well populated ~/bin (well ~/usr/bin) and many shell functions, i will adopt that practice. it might even work out for script files (i.e. recordings of your shell session).
Re:Using hashtags to organize your bash history by drdaeman on Sunday June 30, 2013 @08:52AM (#5965599)
> not good enough to open an editor for

It's just a keystroke away (`C-x C-e` in bash and zsh, in emacs-like line editing mode) if you have $EDITOR set properly.

Re:Using hashtags to organize your bash history by ibotty on Sunday June 30, 2013 @01:11PM (#5966366)
that's interesting. i did not know that shortcut (well, it doesn't work with vi keybindings), but that sounds useful. that was not the whole point though.
Re:Using hashtags to organize your bash history by kragniz on Sunday June 30, 2013 @02:04PM (#5966576)
Using vi keybindings, <esc>v does the same.
Re:Using hashtags to organize your bash history by ibotty on Sunday June 30, 2013 @04:33PM (#5967076)
not in my zsh.
Re:Using hashtags to organize your bash history by zaptheimpaler on Sunday June 30, 2013 @08:32AM (#5965557)
I think this approach is cleaner and you have the added advantage of having a permanent stash of useful commands you can move around systems.

Personally, I would use the hashtags, and also use something like inotify to automatically add any hashtagged commands to seperate scripts and store them in something like ~/usr/bin/custom/

Re:Using hashtags to organize your bash history by pyre on Sunday June 30, 2013 @10:28AM (#5965888)
It depends on how large your shell history is. I often have useful commands scrolled out of my history just because I got busy doing something orthogonal that involved a lot of shell commands.
Re:Using hashtags to organize your bash history by samatman on Sunday June 30, 2013 @02:39PM (#5966692)
What you are describing is persisting a command; the parent article describes a caching technique.

Caching a name for a command, as you issue it, makes it easier to retrieve later if you decide you want it as a proper script or alias. Among other things.