• Posts
  • RSS
  • ◂◂RSS
  • Contact

  • Shell usage

    July 2nd, 2009
    shell, programming, tech  [html]
    I've been reading archives of Wandering Thoughts, the blog of a UToronto sysadmin. Lots of interesting ideas. Reading PersistentVsDisposableUsage, in which he claims that most people either open a new shell for each task or use the same set of long running shells for multiple tasks, I realized I fall pretty squarely into the second category. I keep shells open that fill the desktop space, and use whichever one is free. But where I should be, really, is "shell per task", where when doing one class of thing I use a specific shell instance. This would keep history straight.

    I also started thinking about what Sameer does with history: all commands typed go both into a full history file somewhere and a .local_history file in the current directory. The local_history idea I don't like, as it clutters things up a lot, but a full history that's more robust than the shell history would be nice. So I added the lines below to my prompt function in bash:

    echo "$(date +%Y-%m-%d--%H-%M-%S) $(hostname) $PWD $(history | tail -n 1)" >> ~/.full_history
    I think this should work, but it's possible that with appending from multiple places at once it will get clobbered at some point.

    I also thought about what commands do I run:

        $ cat combined-history | awk '{print $2}' | susrn | head
        619 ls
        516 find
        413 cat
        304 python
        275 cd
        216 svn
        215 rm
        199 more
        130 for
        122 svc
        
    Alternately, taking into account all the compound commands I run by looking at the commands following pipe and semicolon in addition to line starters:
        $ cat combined-history | sed s/'[;|]'/'\nNNN '/g | awk '{print $2}'| susrn | head -n 12
        881 grep
        620 ls
        544 do
        536 done
        535 sed
        524 find
        501 python
        465 cat
        412 while
        315 head
        283 cd
        291 more
        
    (combined-history is the result of running history in each shell)

    Notes:

    • I invoke most python scripts with python instead of a shebang. I use a lot of python.
    • I leave emacs running most of the time in its own windows. So it doesn't show up.
    • The command svc is svn commit
    • The do and done entries are higher than while because I sometimes use for. The do entry is higher than the done one because I leave off final done more than I'd like. I extended the second one to 12, in case you don't want to look at do and done.
    • While I realize there are performance reasons not to, I use cat $fname | cmds all the time. It's much more consistent because then everything follows the same pattern. Bash could consider optimizing "cat single-arg | cmds" to "< single-arg cmds".

    Comment via: facebook

    Recent posts on blogs I like:

    Learning Worst Industry Practices

    If I have a bad idea and you have a bad idea and we exchange them, we now have two bad ideas. But more than that. If I have a bad idea and you have a good idea and we exchange them, we should both land on your good idea – but that requires both […]

    via Pedestrian Observations September 20, 2020

    Collections: Iron, How Did They Make It? Part I, Mining

    This week we are starting a four-part look at pre-modern iron and steel production. As with our series on farming, we are going to follow the train of iron production from the mine to a finished object, be that a tool, a piece of armor, a simple nail, a w…

    via A Collection of Unmitigated Pedantry September 18, 2020

    Learning Game

    I came up with this game. In the game one person thinks of something and then gives the other person a clue. And the other person writes a guess down on a blackboard or a piece of paper. Or really anything you have that's laying around that's av…

    via Lily Wise's Blog Posts September 17, 2020

    more     (via openring)


  • Posts
  • RSS
  • ◂◂RSS
  • Contact