Useful scripts

This commit is contained in:
eeva 2016-03-18 17:59:50 +01:00
parent cdcb99614b
commit 3f8dc335a0
4 changed files with 140 additions and 0 deletions

24
scripts/prefix/bin/coc Executable file
View file

@ -0,0 +1,24 @@
#!/bin/sh
#
# "coc" stands for "compile on change" and runs the supplied compile
# command when the given list of files is changed.
#
# coc [command] [fileToCompile] [filesToWatch]
#
# If no explicit list of files to watch is given, fileToCompile is
# watched.
command=$1
file=$2
shift 2
watchedFiles=$@
if [ -z "$watchedFiles" ] ; then
watchedFiles=$file
fi
while true ; do
date
inotifywait -e modify $watchedFiles
$command $file
done

74
scripts/prefix/bin/mvln Executable file
View file

@ -0,0 +1,74 @@
#!/bin/bash
# Moves and links a file back at its initial location
# It can not cross filesystems!
#
# Usage: mvln PATH1 PATH2
# Depends on: realpath, basename, dirname
if [[ $# -ne 2 ]]
then
echo "Usage: mvln <PATH1> <PATH2>"
exit 0
fi
# Step 1: building full path out of both arguments #############################
[[ $1 =~ ^/ ]] && F1=$1 || F1=$(realpath -s $1)
[[ $2 =~ ^/ ]] && F2=$2 || F2=$(realpath -s $2)
# Step 2: enumerating all interesting cases ####################################
# PATH1 can be:
if [[ -f $F1 ]]
then STATE1="0" # a regular file
elif [[ -d $PWD/$F1 ]]
then STATE1="1" # a directory
elif [[ -e $F1 ]]
then STATE1="8" # an other kind of file
else STATE1="9" # a non-existent file
fi
# PATH2 can be:
if [[ -d $F2 ]]
then STATE2="0" # a directory
elif [[ -d $(dirname $F2) ]]
then STATE2="1" # a non-existent file in an existent directory
elif [[ -e $F2 ]]
then STATE2="8" # any other kind of file
else STATE2="9" # a non-existent file in a non-existent directory
fi
# Step 3: eat this my little state automaton ###################################
STATE="$STATE1$STATE2"
case $STATE in
[89]* )
echo "$F1 is not a proper file (or a non-existent one)"
echo "Note that only regular files and directories are allowed"
exit $STATE
;;
*[89] )
echo "$F2 can not be created (containing directory does not exist)"
echo "or exists already (refusing to overwrite)"
exit $STATE
;;
[01]0 ) # file or dir to an existing dir
DEGUB="File/Dir to same name in existing dir"
PATH1=$F1
PATH2=$F2/$(basename $F1)
;;
[01]1 ) # file to new file name in an existing dir
DEGUB="File/Dir to new name in existing dir"
PATH1=$F1
PATH2=$F2
;;
* )
echo "Uncaught error (this is f*****g bad)"
exit $STATE
;;
esac
#echo $DEGUB
# Step 4: eventually act upon gathered knowledge ###############################
mv $PATH1 $PATH2
cd $(dirname $PATH1)
ln -s $PATH2 $(basename $PATH1)

33
scripts/prefix/bin/vpn Executable file
View file

@ -0,0 +1,33 @@
#!/bin/sh
if [[ $# -ne 1 ]]
then
echo "$(basename $0) requires exactly one of: hard, medium, off"
exit 1
else
case $1 in
"hard")
PROFILE="2947fbbad4"
;;
"medium")
PROFILE="OodCanine"
;;
"off")
;;
*)
echo "Wrong command, either hard, medium or off"
exit 2
;;
esac
sudo systemctl stop openvpn@2947fbbad4.service
sudo systemctl stop openvpn@OodCanine.service
sleep 1s
if [[ -n $PROFILE ]]
then
sudo systemctl start openvpn@$PROFILE.service
fi
echo "$PROFILE started"
fi

View file

@ -0,0 +1,9 @@
#!/bin/sh
pos="$1"
pdffile="$2"
zathura --synctex-forward "$pos" "$pdffile" || \
(
zathura -x "emacsclient --eval '(progn (find-file \"%{input}\") (goto-line %{line}))'" "$pdffile" &
sleep 1; zathura --synctex-forward "$pos" "$pdffile" )
exit