Bashing kate sessions

I wondered how many files no longer existed in my old kate sessions and since I learned how to shell script it seemed appropriate to use that skill to answer the question. I use the script below piped to wc -l to see generally how many elements are there and which do not exist anymore. Kind of like a link checker. It is reality rot , I guess. Like all those stupid ideas that seem real when you are a child and they hang about like an old web page with more dead links than live.

I suppose I could have done it in python but that extra 6 characters stopped me and these shell scripts practically write themselves as soon as I think of a concept. I have noticed that I use better indentation style in my C code and shell scripts since I learned python programming.

One odd thing I learned from this is that if kate stores a file name with a space in it, it is stored as %2520, which translates to %20, which then translates to space. I try to avoid file names with spaces because it seems to confuse some programs or scripts on occasion.

#!/usr/bin/env bash

function exists {
 for s in `cat *.katesession |grep URL= | cut -d "=" -f2 | cut -d ":" -f2`
 do
  if [ `echo $s | grep  "///" ` ];
  then
   if [ -e $s ];
    then
    echo -ne ""
   else
    echo $s "Does not exist" 
   fi
  fi
 done
}
function present {
 for s in `cat *.katesession |grep URL= | cut -d "=" -f2 | cut -d ":" -f2`
 do
  if [ `echo $s | grep  "///" ` ];
  then
   echo $s " Referenced" 
  fi
 done
}

if [ $1 == "missing" ];
then
 exists
fi
if [ $1 == "all" ];
then
 present
fi
echo $1
exit 0

0 comments:

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen