Makes you look busy

alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
This makes an alias for a command named 'busy'. The 'busy' command opens a random file in /usr/include to a random line with vim. Drop this in your .bash_aliases and make sure that file is initialized in your .bashrc.

22
By: busybee
2010-03-09 21:48:41

1 Alternatives + Submit Alt

  • Enhancement for the 'busy' command originally posted by busybee : less chars, no escape issue, and most important it exclude small files ( opening a 5 lines file isn't that persuasive I think ;) ) This makes an alias for a command named 'busy'. The 'busy' command opens a random file in /usr/include to a random line with vim.


    0
    alias busy='rnd_file=$(find /usr/include -type f -size +5k | sort -R | head -n 1) && vim +$((RANDOM%$(wc -l $rnd_file | cut -f1 -d" "))) $rnd_file'
    frntn · 2011-10-16 00:05:59 0

What Others Think

i like the idea :D
RanyAlbeg · 453 weeks and 6 days ago
Fails here due to sort not knowing -R. CentOS 5.3 sort (GNU coreutils) 5.97
DaveQB · 453 weeks and 5 days ago
It always takes me to the last line because the braces in the awk statement aren't properly escaped for zsh by the doublequotes. The following works for me: my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk '{print $1}'); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file
tremby · 453 weeks and 4 days ago
Oops -- actually, in the alias statement as you wrote it it does in fact work fine. Interesting. My post above applied when using the body of the command alone on the commandline.
tremby · 453 weeks and 4 days ago
Wow. That takes me back to the days when video games had "boss keys" that would show a fake spreadsheet or some such business-baloney. Of course, if you're at a command line, as this command assumes, I'm not quite sure what you'd want to hide from your boss... ASCII art Pr0n?
hackerb9 · 453 weeks and 3 days ago
you must add a backspace to escape the $ character in the awk argument and make it work: alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
fsilveira · 440 weeks and 6 days ago
you must add a backspace to escape the $ character in the awk argument and make it work: alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print \$1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
fsilveira · 440 weeks and 6 days ago
sorry, it works either way, but my fix makes the vim line jump work as expected by the author. (is there a way to remove my first reply?)
fsilveira · 440 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: