Tag Archives: shell

false

K. Mandla writes on false:

In fact, it’s anything but helpful. It won’t take help flags. It does what it’s supposed to do, but does it unsuccessfully, every time.

Even the man page tells you that. What’s false? Every time, that’s what. Hardly helpful. Hardly useful. Just … false.

It must be really hard when people expect you to be unsuccessful. :neutral:

c for cat

An year-old tweet from @paul_irish:

Beautiful!

Countdown timer shell script

I made a small countdown script for the shell. It goes as follows:

Some tricks used in the script include:

  1. echo -ne "blah blah \r" was used to write in the same line over and over
  2. That 19800 is the time difference from GMT 0.0 in seconds. In Sri Lanka, it’s 5.30 hrs. Yes, we’re dealing with epoch time here, but still trying to figure out why we need to offset the time difference. :???:
  3. notify-send sends a desktop notification
  4. zenity --info pops up a message box

You can also add a sound to play with mplayer.

ShellCheck – static analyzer for shell scripts

Just came across ShellCheck. From its About page:

ShellCheck is a static analysis and linting tool for sh/bash scripts. It’s mainly focused on handling typical beginner and intermediate level syntax errors and pitfalls where the shell just gives a cryptic error message or strange behavior, but it also reports on a few more advanced issues where corner cases can cause delayed failures.

Interestingly, the tool’s completely written with Haskell. You can copy/paste the script on the site, or even install it so you can conveniently check shell scripts every now and then. You need cabal to have installed to compile the source. On Debian, you can install the package haskell-platform to install cabal.

pkill script for cygwin

pkill is a basic necessity of life. For cygwin, this comes in the package procps which is not available for x64. You can of course ps and grep then awk but who has the time.

This small script from cygwin mailing list archives to the rescue:

tskill is actually a kill equivalent in the Windows world.

csh woes

One thing I hate about the C Shell is the lack of function support. You’re left with aliases but they don’t work out all the time.

The other I wanted to add the git branch you’re on to the csh (tcsh, in fact) prompt. I tried out adding the following to the .cshrc:

alias GIT_BRANCH_CMD "sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* (.*)/(1)/'"
alias cd 'chdir !*;set prompt=`whoami`@`hostname`": %~"`GIT_BRANCH_CMD`" > "'
cd ~

But it only works when you cd to the directory. Out of luck when you git checkout, etc. To my knowledge csh has no advantage over bash, so the lesson is to use bash whenever possible.