A few scripts and aliases

I don’t use many aliases, although I know they are quite popular with some people. In general I have only two or three, which I use mostly because they’re coupled with some scripts that open or trigger a program in a particular way.

For example, I’m on an elinks kick these days. It’s fast, it’s fun and it works marvellously alongside screen and dvtm.

But I don’t like browsers that don’t clean up after themselves. I don’t like all-or-nothing cookie management, or goto lists or search histories. And so, for an alias, I use this:

alias elinks='$HOME/.scripts/elinks.sh'

That triggers an executable script in a hidden folder, and this it what’s in it:

#!/bin/bash
/usr/bin/elinks $1
rm $HOME/.elinks/gotohist $HOME/.elinks/searchhist 2>/dev/null
cp $HOME/.elinks/cookies.edit $HOME/.elinks/cookies

The first line tags it as a bash script. The next line triggers elinks and passes any address to it that I might have wanted as a start page.

When it’s done, the search history and the goto history are removed, with whatever feedback shuffled off to /dev/null (because those commands show an error message if the file doesn’t exist and can’t be deleted).

After that, a pristine cookie file is copied into place. The idea there is that there are some cookies that I care to keep — forum sign-ins or blog sign-ins — and those are in the cookies.edit file.

That way, when I’m done, the cookies I accrued through the course of my surfing are eradicated with a clean list, ready when I start elinks again. The only downside is that with two browsers open, if one of them exits, the cookies for both are reset. Just so you know. …

Here’s another example. I set the volume manually on my machine, usually at start time, with the amixer commands. But I have two aliases — usually called ‘volmute’ and ‘volreset’ — that trigger two more scripts. Here’s ‘mute.sh’.

#!/bin/bash
amixer sset PCM mute
amixer sset Master mute

And of course, ‘volumes.sh’.

#!/bin/bash
amixer sset PCM 50% unmute
amixer sset Master 90% unmute

With those two I can manage the general volume on moc or another audio source (like MPlayer) without hunting down the application in use. I type one word and the system falls mute (good for when the phone rings), and type another to reset it to a comfortable level.

I have a few others, but they’re not stellar, or they follow the examples of one I already explained, like a script that cleans up after emelfm2 and restores some settings. I’ll never be accused of being a master scripter, but little things like this are occasionally useful. :mrgreen:

3 thoughts on “A few scripts and aliases

  1. IceBrain

    I use a “mute” alias too, but it toggles the mute setting, so a second call restores the volume to the same level it was.

    I use a “mkcd” too, which calls mkdir $1 && cd $1, so I can make a directory and change to it directly.

    But my most elaborate alias (which is not exactly an alias, it’s a ZSH function) is “tube”, which runs a python script that searches for the given keywords in youtube and returns the video URL, which is then passed to mplayer running in a hidden screen session đŸ˜›

    Reply
  2. Tom Adams

    I use mkdir/cd too. Very handy.

    I also have an alias to run an HTTP server which serves . as the document root.

    alias srv=”ruby -rwebrick -e ‘s=WEBrick::HTTPServer.new(:Port=>8080,\
    :DocumentRoot=>Dir::pwd);trap(\”INT\”){s.shutdown};s.start'”

    I’m very happy about WEBrick being included in Ruby. Means it works everywhere. Great for ad-hoc file sharing between machines and/or people on the same network (handy for streaming, letting housemates download files).

    Reply
  3. karthik

    I don’t know if you use elinks to open multiple URLs in tabs. (I do.) In any case, it’s a simple fix to generalize the elinks script a bit:

    #!/bin/bash
    /usr/bin/elinks $*

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s