[HowTo] Delete vim's backup files

In general, vim's auto backup function (:set backup) is a rather useful feature that saved me, or more precisely, some of my files several times. Nevertheless, all these files with an appended tilde, flooding your filesystem, are quite annoying. So, here's a way to get rid of all these files in one go:

#find all backup files in your home directory
find ~ -name "*~"
#find and delete all backup files in your home directory
find ~ -name "*~" -delete
#find all backup files and delete them only if the original files exist!
find ~ -name "*~" -exec bash -c '[ -e "${1%?}" ] && rm -f -- "$1";' _ {} \;

yaydl 0.8.7a (update)

A new alpha-version of yaydl is available now. Downloading videos from youtube, myvideo and metacafe should work fine, whereas the support for clipfish is currently on hold. BTW: A final version will be released along with DNF ;-) UPDATE: I've just finished my work on version 0.8.7a - everything should be working fine again. :-)

Download the latest version

What's my public IP?

Here are 2 ways, to determine your public IP address using curl, sed and grep. I recommend using the second one.

curl -s www.wieistmeineip.de | grep class=\"ip\" | sed -r 's#(.*>)(.*)(<.*)#\2#'
curl -s checkip.dyndns.org | sed -r 's#(.*: )([0-9.]*)(<.*)#\2#'

Useful bash functions II

Most perl scripts I write start like this:

#!/usr/bin/perl
use strict;
use warnings;
#maybe the GPL or some other stuff...

Additionally it's always required to set the "x flag" via chmod - all in all quite annoying. That's why I added the function shown below to my ~/.bashrc

np() {
    gplfile=~/Dokumente/gpl.txt
    if [ $# -eq 0 ]
    then
        echo "filename required..."
        return
    fi
    if [ -e "$1" ]
    then
        echo "file already exists!"
        return
    fi
    touch "$1" || { echo "can't touch $1" ; return ; }
    echo "#!/usr/bin/perl" >> "$1"
    if [ "$2" = "gpl" ] && [ -e "$gplfile" ]
    then
        cat "$gplfile" >> "$1"
    fi
    echo "" >> "$1"
    echo "use strict;" >> "$1"
    echo "use warnings;" >> "$1"
    echo "use 5.10.0;" >> "$1"
    echo "use feature 'say';" >> "$1"
    echo "" >> "$1"
    chmod 700 "$1"
    [ $EDITOR ] || EDITOR=vim
    $EDITOR "$1"
}

Usage: np filename [gpl]

Useful bash functions I

Put the following in your ~/.bashrc

up() {
    if [ $# == 0 ]
    then
        cd ..
        return
    fi
    if [ "${1//[^0-9]/}" != "$1" ]
    then
        echo "Not a number"
        return
    fi
    STRING=""
    for (( i=0; i<$1 ; i++ ))
    do
        STRING="$STRING../"
    done
    cd $STRING
}

up is equivalent to cd .. and up N jumps up N directories in the directory tree.

Battery status script

Some weeks ago, my laptop suddenly turned off, because its battery was completely flat. To prevent this from happening again, I wrote a small script that notifies me, when a critical charge state is reached. Additionally it shuts the computer down before the battery does. ;-) Please note that this isn't meant to be a general purpose solution, so feel free to adapt it to your own needs.

Download