Faster zshrc

This commit is contained in:
Thomas Forgione 2019-02-11 17:40:33 +01:00
parent 23e40963ba
commit 740857f59b
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
8 changed files with 88 additions and 176 deletions

View File

@ -18,12 +18,6 @@ alias cake="cmake"
# My pdf reader # My pdf reader
alias pdf="evince" alias pdf="evince"
# Auto color on pacman
command -v pacman > /dev/null 2>&1
if [ $? -eq 0 ]; then
alias pacman='pacman --color=auto'
fi
# clean for cmake files # clean for cmake files
alias cclean='rm -rf `find . -name "CMakeCache.txt"` `find . -name "cmake_install.cmake"` `find . -name "CMakeFiles"` `find . -name "Makefile"`' alias cclean='rm -rf `find . -name "CMakeCache.txt"` `find . -name "cmake_install.cmake"` `find . -name "CMakeFiles"` `find . -name "Makefile"`'
@ -52,6 +46,11 @@ alias j="jump"
# Disable bat paging # Disable bat paging
alias bat="bat --paging=never" alias bat="bat --paging=never"
# mkdir && cd
mkcd() {
mkdir $1 && cd $1
}
# Initialize thefuck # Initialize thefuck
command -v thefuck > /dev/null 2>&1 command -v thefuck > /dev/null 2>&1

8
zsh/bin/copy Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env zsh
if [ $# -eq 0 ]; then
xclip -selection c
else
file_type=$(file -b --mime-type "$1")
xclip -selection c -t $file_type < $1
fi

9
zsh/bin/swap Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env zsh
# Swap files
swap() {
local tmp=`mktemp`
mv "$1" "$tmp"
mv "$2" "$1"
mv "$tmp" "$2"
}

67
zsh/update.zsh → zsh/bin/update Normal file → Executable file
View File

@ -1,3 +1,13 @@
#!/usr/bin/env zsh
_check_date_if_format() {
local format=`_date_format`
if [ "$format" != "" ]; then
_check_date $format
fi
}
_date_format() { _date_format() {
case $UPDATE_CHECK in case $UPDATE_CHECK in
@ -200,37 +210,46 @@ update-dotfiles() {
echo "\033[32;1m=== Dotfiles updated in $formatted ===\033[0m" echo "\033[32;1m=== Dotfiles updated in $formatted ===\033[0m"
} }
update() { main() {
start=`date +%s` if [ $# -eq 0 ]; then
echo "\033[32;1m=== Starting update ===\033[0m"
# Update the system start=`date +%s`
update-system echo "\033[32;1m=== Starting full update ===\033[0m"
# Update rust and rust packages # Update the system
update-rust update-system
# Update the dotfiles # Update rust and rust packages
update-dotfiles update-rust
seconds=$((`date +%s` - $start )) # Update the dotfiles
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` update-dotfiles
echo "\033[32;1m=== Update finished in $formatted ===\033[0m"
format=`_date_format` format=`_date_format`
if [ $? -eq 0 ]; then
_check_date_file
date $format > ~/.config/dotfiles/.data/update_date
fi
seconds=$((`date +%s` - $start ))
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
echo "\033[32;1m=== Update finished in $formatted ===\033[0m"
else
case $1 in;
"system") update-system;;
"rust") update-rust;;
"dotfiles") update-dotfiles;;
"check") _check_date_if_format;;
esac
if [ $? -eq 0 ]; then
_check_date_file
date $format > ~/.config/dotfiles/.data/update_date
fi fi
} }
# Spawn anonymous function main $@
function() {
local format=`_date_format`
if [ "$format" != "" ]; then
_check_date $format
fi
}

16
zsh/bin/vim-recover Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env zsh
# Check recovery directory from vim
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

View File

@ -1,144 +0,0 @@
# Some helping functions
### File manipulation ###
# Copy to clipboard
copy() {
if [ $# -eq 0 ]; then
xclip -selection c
else
file_type=$(file -b --mime-type "$1")
xclip -selection c -t $file_type < $1
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"
}
vs() {
v $1 -c ":vs $2"
}
sp() {
v $1 -c ":sp $2"
}
vfind() {
v `find . -name "$1"`
}
### Others ###
# Recover a vim backup
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
}
# 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 Cloudflare/APNIC's dns
resolv() {
echo 'nameserver 1.1.1.1' | sudo tee /etc/resolv.conf > /dev/null
}
# Generate a standard LaTeX maefile
makelatex() {
cp /home/thomas/.script/classgen/Makefile.latex ./Makefile
}
# 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
}
source $HOME/.config/dotfiles/zsh/update.zsh
source $HOME/.config/dotfiles/zsh/gclone.zsh
# Music things
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
echo "require('music').execute_command(\"$command\")" | awesome-client
else
library_path=$(realpath $2 | cut -d '/' -f 5-)
awesome_command="require('music').execute_command(\"$command\",\"$library_path\")"
echo $awesome_command | awesome-client
fi
}
alias mcf="music-client file"
fi
fi
fi

View File

@ -2,6 +2,7 @@
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH
# The scripts path # The scripts path
export PATH=$DOTFILES/zsh/bin:$PATH
if [ -d "$HOME/.scripts" ]; then if [ -d "$HOME/.scripts" ]; then
export PATH=$HOME/.scripts:$PATH export PATH=$HOME/.scripts:$PATH
fi fi
@ -14,7 +15,10 @@ fi
# Nvm path # Nvm path
if [ -d $HOME/.nvm ]; then if [ -d $HOME/.nvm ]; then
export NVM_DIR="$HOME/.nvm" export NVM_DIR="$HOME/.nvm"
source $NVM_DIR/nvm.sh # Sourcing this is really slow
# source $NVM_DIR/nvm.sh
# So well just export the path
export PATH=$HOME/.nvm/versions/v11.4.0/bin:$PATH
fi fi
# LD_LIBRARY_PATH: I don't know why there is this line here but I'm too scared # LD_LIBRARY_PATH: I don't know why there is this line here but I'm too scared

3
zshrc
View File

@ -18,8 +18,9 @@ source $DOTFILES/zsh/config.zsh
source $DOTFILES/zsh/path.zsh source $DOTFILES/zsh/path.zsh
source $DOTFILES/zsh/exports.zsh source $DOTFILES/zsh/exports.zsh
source $DOTFILES/zsh/aliases.zsh source $DOTFILES/zsh/aliases.zsh
source $DOTFILES/zsh/functions.zsh
if [ -f $DOTFILES/zsh/extraconfig.zsh ]; then if [ -f $DOTFILES/zsh/extraconfig.zsh ]; then
source $DOTFILES/zsh/extraconfig.zsh source $DOTFILES/zsh/extraconfig.zsh
fi fi
update check