2016-08-22 11:04:24 +01:00
|
|
|
# Some helping functions
|
|
|
|
|
|
|
|
### File manipulation ###
|
|
|
|
# Copy to clipboard
|
|
|
|
copy() {
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
xclip -selection c
|
|
|
|
else
|
2018-06-06 13:42:57 +01:00
|
|
|
file_type=$(file -b --mime-type "$1")
|
|
|
|
xclip -selection c -t $file_type < $1
|
2016-08-22 11:04:24 +01:00
|
|
|
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 09:57:28 +00:00
|
|
|
vs() {
|
2016-08-22 11:04:24 +01:00
|
|
|
v $1 -c ":vs $2"
|
|
|
|
}
|
2017-03-20 09:57:28 +00:00
|
|
|
sp() {
|
|
|
|
v $1 -c ":sp $2"
|
|
|
|
}
|
2016-08-22 11:04:24 +01:00
|
|
|
vfind() {
|
|
|
|
v `find . -name "$1"`
|
|
|
|
}
|
|
|
|
|
|
|
|
### Others ###
|
2018-09-25 15:27:41 +01:00
|
|
|
# Recover a vim backup
|
|
|
|
recover() {
|
|
|
|
if [ -f $1 ]; then
|
|
|
|
echo >&2 Cannot recover an existing file...
|
2018-10-11 07:03:27 +01:00
|
|
|
return 1
|
2018-09-25 15:27:41 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
BACKUP_PATH=~/.vim/backups/`echo $PWD/$1 | tr '/' '%'`
|
|
|
|
|
|
|
|
if [ ! -f "$BACKUP_PATH" ]; then
|
|
|
|
echo >&2 Backup not found...
|
2018-10-11 07:03:27 +01:00
|
|
|
return 2
|
2018-09-25 15:27:41 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
cp $BACKUP_PATH $1
|
|
|
|
}
|
|
|
|
|
2016-08-22 11:04:24 +01:00
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
2018-08-31 12:16:01 +01:00
|
|
|
# Clears resolv.conf with Cloudflare/APNIC's dns
|
2016-08-22 11:04:24 +01:00
|
|
|
resolv() {
|
2018-08-31 12:16:01 +01:00
|
|
|
echo 'nameserver 1.1.1.1' | sudo tee /etc/resolv.conf > /dev/null
|
2016-08-22 11:04:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generate a standard LaTeX maefile
|
|
|
|
makelatex() {
|
|
|
|
cp /home/thomas/.script/classgen/Makefile.latex ./Makefile
|
|
|
|
}
|
2017-09-12 13:19:46 +01:00
|
|
|
|
2018-11-29 14:34:24 +00:00
|
|
|
# Check recovery directory from vim
|
|
|
|
vim-recover() {
|
|
|
|
if [ -f $1 ]; then
|
|
|
|
echo >&2 Cannot recover an existing file...
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
BACKUP_PATH=~/.vim/backups/`echo $PWD/$1 | tr '/' '%'`
|
|
|
|
|
|
|
|
if [ ! -f "$BACKUP_PATH" ]; then
|
|
|
|
echo >&2 Backup not found...
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp $BACKUP_PATH $1
|
|
|
|
}
|
|
|
|
|
2018-09-26 16:12:04 +01:00
|
|
|
source $HOME/.config/dotfiles/zsh/update.zsh
|
2018-09-28 13:04:34 +01:00
|
|
|
source $HOME/.config/dotfiles/zsh/gclone.zsh
|
2017-10-09 10:09:05 +01:00
|
|
|
|
2017-09-12 13:19:46 +01:00
|
|
|
# Music things
|
2017-10-20 10:38:23 +01: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 10:39:35 +01:00
|
|
|
echo "require('music').execute_command(\"$command\")" | awesome-client
|
2017-10-20 10:38:23 +01:00
|
|
|
else
|
2018-06-06 13:42:57 +01:00
|
|
|
library_path=$(realpath $2 | cut -d '/' -f 5-)
|
2017-10-20 10:38:23 +01:00
|
|
|
awesome_command="require('music').execute_command(\"$command\",\"$library_path\")"
|
|
|
|
echo $awesome_command | awesome-client
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-06-06 13:42:57 +01:00
|
|
|
alias mcf="music-client file"
|
|
|
|
|
2017-10-20 10:38:23 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
2017-09-12 13:19:46 +01:00
|
|
|
|