Showing posts with label shell script. Show all posts
Showing posts with label shell script. Show all posts

January 3, 2016

chequePrint : Linux utility to print into cheques

The problem : As I do not write much on paper these days, writing cheques will cause some cheque leaves go waste. Earlier I had created a template in LibreOffice to solve the problem. However, I could not use that template as it was for a different bank. It was too difficult to get the alignment correct as there were boxes for days, month & year.

Solution : Write a script! Initially considered generating TeX files but zeroed in on PostScript as it would be easy to do the layout.
The script is available in the chequePrint GitHub repo.

August 17, 2014

Up!

Like many other scripts, the bash shell function "up" is a by product of my laziness. As the name vaguely indicates, it can move you up in the directory tree. If you want to move 3 levels up in the directory tree, you invoke the function as up 3 instead of cd ../../../  which saves a ton of typing. The shell function can be downloaded from my GitHub repo. 

# Go n level up in the directory structure.
# License : GPLv3
function up ()
{
        lvls=""
        if [[ ! -z "$1" ]]
        then
                for i in `seq $1`
                do
                        lvls="${lvls}../"
                done
        else
                lvls="../"
        fi

        # Will land up in / if n is too large.
        cd ${lvls}
        pwd
}


The ShellUtils repo contains few other shell scripts that might be interesting. See the Readme file in the repo to find out what those scripts are doing.

August 2, 2014

Dbus-MPRIS Music Player Controller

The Short story :
Here is a shell script that can control media players like Amarok, Clementine, mpd & VLC : https://github.com/primejyothi/Dbus-MPRIS-MusicPlayer-Controller

The long story :
Like most of the programmers, I'm a big fan of command line. Since I can touch type, things get done really faster. There will be a music player running in my system and most of the time I will be using mpd with ncmpcpp. Only problem is that I keep forget which key is used to stop/pause ncmpcpp. This problem was quickly resolved by installing mpc and few aliases. Things were pretty fine and I even wrote a script (https://github.com/primejyothi/ShellUtils/blob/master/mpdLyrics.sh) to extract the album art of the song being played in mpd and show it on Conky .

Problems cropped up when Amarok or Clementine were used. The controls were on top for Amarok and in case of Clementine it was just opposite. I could use the media keys in the keyboard, but I hardly use them as mpd does not respond to them. The search of consistency ended with MPRIS. Quickly put together a script and any of these media players could be controlled with a single script. Few aliases and I can control the media player without leaving vim :)

For VLC and mpd, MPRIS need to be enabled manually. The VLC player need to be started as vlc --control dbus. In case of mpd, mpDris2 need to be running.

July 22, 2014

JOSM Preset Builder

I was trying to build some presets for JOSM (https://josm.openstreetmap.de/) few days back and thought it would be a good idea to automate the process. Read the some documentation that was available from http://josm.openstreetmap.de/wiki/TaggingPresets. The defaultpresets.xml contained in the JOSM package gave some very useful information in writing the script.

The idea was to have a text file with the preset data and generate the XML file using a script. I finally settled on a pipe separated file format with embedded key value pairs. When finished, it could generate presets with key value pairs, drop downs and lists.

The scripts and sample files are released under GPLv3 and available at https://github.com/primejyothi/JOSMPresetBuilder

Hope someone will find it useful.

March 25, 2014

ഗാലിഫൈ

പ്രോഗ്രാം കോർഡമ്പ് ചെയ്തോ? കമ്പൈലർ എണ്ണമില്ലാത്ത എററുകൾ തരുന്നോ? ലവൻ നിങ്ങളുടെ കോഡ് കൊളമാക്കിയോ? ഇത്തരം സന്ദർഭങ്ങളിലുപയോഗിക്കാൻ പറ്റിയ തെറികളുണ്ടോ നിങ്ങളുടെ പക്കൽ? ഇല്ലെങ്കിൽ ഇതാ ഗാലിഫൈ സ്ക്രിപ്റ്റ്. പതിനഞ്ച് ഹൈക്വാളിറ്റി ബിൽറ്റിൻ തെറികളുമായി ഗാലിഫൈ സ്ക്രിപ്റ്റ് ഡൗൺലോഡൂ : http://goo.gl/cVKglH
ബിൽറ്റിൻ എന്റ്രികൾ പോര എങ്കിൽ കസ്റ്റം എന്റ്രികൾ ~/.galify.rc എന്ന ഫയലിൽ ചേർക്കാവുന്നതാണ്

ഈ സ്കിപ്റ്റ് എഴുതാനുള്ള പ്രചോദനം സുബിൻ ഡയസ്പോറയിൽ ഇട്ട ഈ പോസ്റ്റാണ് : https://poddery.com/posts/1033614

February 24, 2014

JOSM Tile stitching script

I wrote a Linux shell utility to combine the OpenStreetMap map tiles downloaded by JOSM into a single big image. The script is available here : https://github.com/primejyothi/jMapStitch

May 16, 2012

push & pop - cd made bit easier

During my initial days as developer, I found myself doing cd to folders which were deep in the directory structures often having long names. Long names were not a big problem due to auto completion but remembering different directory names were a problem. The idea of having aliases for cd for different directories was dropped even before writing a single alias as I didn't want to remember the aliases for different directories. So I wrote two scripts named push.sh and pop.sh. The working is pretty simple, you go to a directory which need to be remembered, execute push. The pop script will give a list of remembered directories and based on the choice will take you to the selected directory. I hope you may find this useful. Here are the scripts:

[prime@ford bin]$ cat push.sh 
#! /bin/bash
lines_to_keep=9
data_file=~/.dir.dat
tmp_file=~/.dir.dat.$$ 
tail -"$lines_to_keep" $data_file > $tmp_file
mv $tmp_file $data_file
cur_dir=`pwd`
echo $cur_dir >> $data_file

[prime@ford bin]$ cat pop.sh 
#! /bin/bash
lines_to_keep=9
data_file=~/.dir.dat
tail -"$lines_to_keep" $data_file |nl
echo -e "Choice please : " \\c
read choice
case "$choice" in
[0-9]*)
        ;;
*)
        echo "Invalid choice"
        return 0
        ;;
esac
dest_dir=`tail -"$lines_to_keep" $data_file | head -$choice |tail -1`
cd $dest_dir

Save scripts in a convenient location say ~/bin. The pop.sh script need to run in the current shell the cd to work correctly. This can be either be done by preceding the pop.sh with a dot (not very convenient) or creating an alias which will run the script in the current shell as follows

alias pop='. ~/bin/pop.sh'
alias push='~/bin/push.sh' # Put these aliases in the .bashrc or .profile

Hope you may find it useful. Share and enjoy!*

* "Share and Enjoy" is the slogan of the Sirius Cybernetics Corporation ;)