2016-08-22 12:04:24 +02:00
|
|
|
# Some helping functions
|
|
|
|
|
|
|
|
### File manipulation ###
|
|
|
|
# Copy to clipboard
|
|
|
|
copy() {
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
xclip -selection c
|
|
|
|
else
|
|
|
|
cat $1 | xclip -selection c
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Swap files
|
|
|
|
swap() {
|
|
|
|
local tmp=`mktemp`
|
|
|
|
mv "$1" "$tmp"
|
|
|
|
mv "$2" "$1"
|
|
|
|
mv "$tmp" "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
# mkdir && cd
|
|
|
|
mkcd() {
|
|
|
|
mkdir $1 && cd $1
|
|
|
|
}
|
|
|
|
|
|
|
|
### Vim helpers ###
|
|
|
|
vclass() {
|
|
|
|
v src/"$1".cpp -c ":vs include/$1.hpp"
|
|
|
|
}
|
|
|
|
vide() {
|
|
|
|
v $1 -c ":NERDTree"
|
|
|
|
}
|
2017-03-20 10:57:28 +01:00
|
|
|
vs() {
|
2016-08-22 12:04:24 +02:00
|
|
|
v $1 -c ":vs $2"
|
|
|
|
}
|
2017-03-20 10:57:28 +01:00
|
|
|
sp() {
|
|
|
|
v $1 -c ":sp $2"
|
|
|
|
}
|
2016-08-22 12:04:24 +02:00
|
|
|
vfind() {
|
|
|
|
v `find . -name "$1"`
|
|
|
|
}
|
|
|
|
|
|
|
|
### Awesome functions ###
|
|
|
|
# Wallpaper change
|
|
|
|
wallpaper() {
|
|
|
|
case $1 in
|
|
|
|
'vixen' ) echo "change_wallpaper('vixen.jpg');" | awesome-client;;
|
|
|
|
'vixen2' ) echo "change_wallpaper('vixen2.jpg');" | awesome-client;;
|
|
|
|
'arch' ) echo "change_wallpaper('arch4.png');" | awesome-client;;
|
|
|
|
'harley' ) echo "change_wallpaper('1200custom.png');" | awesome-client;;
|
|
|
|
*) return -1
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
### Others ###
|
|
|
|
# colors for the man pages
|
|
|
|
man() {
|
|
|
|
env LESS_TERMCAP_mb=$(printf "\e[1;31m") \
|
|
|
|
LESS_TERMCAP_md=$(printf "\e[1;31m") \
|
|
|
|
LESS_TERMCAP_me=$(printf "\e[0m") \
|
|
|
|
LESS_TERMCAP_se=$(printf "\e[0m") \
|
|
|
|
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
|
|
|
|
LESS_TERMCAP_ue=$(printf "\e[0m") \
|
|
|
|
LESS_TERMCAP_us=$(printf "\e[1;32m") \
|
|
|
|
man "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Better svn log
|
|
|
|
svn() {
|
|
|
|
case $* in
|
|
|
|
log ) shift 1; command svn log "$@" | less ;;
|
|
|
|
* ) command svn "$@" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# Clears resolv.conf with google's dns
|
|
|
|
resolv() {
|
|
|
|
echo 'nameserver 8.8.8.8' | sudo tee /etc/resolv.conf > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate a standard LaTeX maefile
|
|
|
|
makelatex() {
|
|
|
|
cp /home/thomas/.script/classgen/Makefile.latex ./Makefile
|
|
|
|
}
|
2017-09-12 14:19:46 +02:00
|
|
|
|
2017-10-09 11:09:05 +02:00
|
|
|
# cdg : cd to a git repo
|
|
|
|
if [ -d "$GCLONE_PATH" ]; then
|
|
|
|
cdg() {
|
|
|
|
if [ $# -ne 1 ]; then
|
|
|
|
echo "This function expects a single parameter"
|
|
|
|
return 1
|
|
|
|
else
|
2017-11-09 09:55:18 +01:00
|
|
|
found_dirs=`find $GCLONE_PATH -maxdepth 3 -name $1 | sort`
|
|
|
|
total=`echo $found_dirs | wc -l`
|
2017-10-09 11:09:05 +02:00
|
|
|
|
2017-11-09 09:55:18 +01:00
|
|
|
if [[ "" == "$found_dirs" ]]; then
|
2017-10-09 11:09:05 +02:00
|
|
|
echo "$1 not found"
|
|
|
|
return 2
|
2017-11-09 09:55:18 +01:00
|
|
|
elif [ $total -gt 1 ]; then
|
|
|
|
counter=0
|
|
|
|
echo "Multiple entries for $1 found:"
|
|
|
|
echo $found_dirs | while read found_dir; do
|
|
|
|
counter=$(($counter+1))
|
|
|
|
echo "["$counter"]" $found_dir
|
|
|
|
done
|
|
|
|
read choice
|
|
|
|
if [[ "$choice" == "" ]]; then
|
|
|
|
cd `echo $found_dirs | head -1 | tail -1`
|
|
|
|
elif [[ "$choice" =~ '^[0-9]+$' ]] && [ $choice -le $total ] && [ $choice -gt 0 ]; then
|
|
|
|
cd `echo $found_dirs | head -$choice | tail -1`
|
|
|
|
else
|
|
|
|
echo "I expected a number that was less than the max..."
|
|
|
|
return 3
|
|
|
|
fi
|
2017-10-09 11:09:05 +02:00
|
|
|
return 3
|
|
|
|
else
|
2017-11-09 09:55:18 +01:00
|
|
|
cd $found_dirs
|
2017-10-09 11:09:05 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_cdg() {
|
|
|
|
_arguments "1: :($(find $GCLONE_PATH -maxdepth 3 -exec basename {} \;))"
|
|
|
|
}
|
|
|
|
|
|
|
|
compdef _cdg cdg
|
2017-11-23 20:11:51 +01:00
|
|
|
|
|
|
|
alias mcf="music-client file"
|
2017-10-09 11:09:05 +02:00
|
|
|
fi
|
|
|
|
|
2017-09-12 14:19:46 +02:00
|
|
|
# Music things
|
2017-10-20 11:38:23 +02:00
|
|
|
command -v music-server > /dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
|
|
|
|
# If music-server is installed, check if awesome is running with screenfetch
|
|
|
|
command -v screenfetch > /dev/null 2>&1
|
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
|
|
|
|
screenfetch -d wm -nN | grep "Awesome" > /dev/null 2>&1
|
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
|
|
|
|
# User is running awesome, music-client will go through awesome-client
|
|
|
|
music-client() {
|
|
|
|
command=$1
|
|
|
|
if [ $# -eq 1 ]; then
|
2017-10-20 11:39:35 +02:00
|
|
|
echo "require('music').execute_command(\"$command\")" | awesome-client
|
2017-10-20 11:38:23 +02:00
|
|
|
else
|
|
|
|
library_path=$(realpath $2 | rev | cut -d '/' -f -3 | rev)
|
|
|
|
awesome_command="require('music').execute_command(\"$command\",\"$library_path\")"
|
|
|
|
echo $awesome_command | awesome-client
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
2017-09-12 14:19:46 +02:00
|
|
|
|