

Using hashtags to organize your bash history - vigneshv_psg
http://vignesh.foamsnet.com/2013/06/using-hash-tags-to-organize-bash-history.html

======
mooism2
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?

~~~
twic
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.

~~~
mooism2
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.

~~~
jpk
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](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.

------
pyre
The phplint example isn't a great one. If you use phplint enough you should
either:

1) Create a generic shell script as others have stated.

2) Create a Makefile for your projects with a 'lint' target. If you create
many different PHP projects, consider a project template directory with a
Makefile that already has this, so that every new project automatically has
the functionality:

    
    
      make lint
    

This idea has been around though. I can't recall if I've seen tagging used
before, but saving an unexecuted commandline in the shell history by
commenting it out is another useful hack that's been around a while.

~~~
scribu
The technique might have been around for a while, but it's the first time it
made the connection in my head between twitter hashtags and bash comments, so
+1 to the OP.

------
thejsjunky
For stuff like the example where you know you will be reusing the command,
it's better to use an alias or script. Even if it's just a command you plan to
run in a couple times in a row you can add a temporay alias with: alias foo =
"!!" \- that way you don't have to hit ctrl+r each time.

Still, it's a good tip in terms of adding comments to unusual/confusing
commands so when you go through your history you're not like "wtf was I doing
here?" or if you unexpectedly need to recall it.

------
catenate
This response explains how I use Acme to store (and later modify) commands in
files in each directory.

[https://news.ycombinator.com/item?id=5566567](https://news.ycombinator.com/item?id=5566567)

In addition, I wrote a generic tag-indexing tool (in Plan 9's rc and Inferno's
sh) to find random bits of information (including commands) without caring
where they live in my file hierarchy.

[https://github.com/catenate/notabene](https://github.com/catenate/notabene)

[http://swtools.wordpress.com/2010/03/05/nb%E2%80%94search-
an...](http://swtools.wordpress.com/2010/03/05/nb%E2%80%94search-and-index-
notes-in-files-by-keyword/)

------
thedeer
This is neat! I appreciate using something like hashtags in an unexpected, but
useful way. And as for the comments saying the example should just be put in a
shell script, that's not really relevant at all. The article has nothing to do
with the merits of simple shell scripts versus a fun and useful hack.

------
portmanteaufu
hee hee, "bashtags."

------
twic
This is a cute hack.

