From 740857f59bac7f483b83937b6ca3dbba8ce59e18 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Mon, 11 Feb 2019 17:40:33 +0100 Subject: [PATCH] Faster zshrc --- zsh/aliases.zsh | 11 ++- zsh/bin/copy | 8 ++ zsh/bin/swap | 9 +++ zsh/{update.zsh => bin/update} | 67 +++++++++------ zsh/bin/vim-recover | 16 ++++ zsh/functions.zsh | 144 --------------------------------- zsh/path.zsh | 6 +- zshrc | 3 +- 8 files changed, 88 insertions(+), 176 deletions(-) create mode 100755 zsh/bin/copy create mode 100755 zsh/bin/swap rename zsh/{update.zsh => bin/update} (86%) mode change 100644 => 100755 create mode 100755 zsh/bin/vim-recover delete mode 100644 zsh/functions.zsh diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index 39b881d..6c67023 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -18,12 +18,6 @@ alias cake="cmake" # My pdf reader 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 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 alias bat="bat --paging=never" +# mkdir && cd +mkcd() { + mkdir $1 && cd $1 +} + # Initialize thefuck command -v thefuck > /dev/null 2>&1 diff --git a/zsh/bin/copy b/zsh/bin/copy new file mode 100755 index 0000000..d32a86b --- /dev/null +++ b/zsh/bin/copy @@ -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 diff --git a/zsh/bin/swap b/zsh/bin/swap new file mode 100755 index 0000000..f595788 --- /dev/null +++ b/zsh/bin/swap @@ -0,0 +1,9 @@ +#!/usr/bin/env zsh + +# Swap files +swap() { + local tmp=`mktemp` + mv "$1" "$tmp" + mv "$2" "$1" + mv "$tmp" "$2" +} diff --git a/zsh/update.zsh b/zsh/bin/update old mode 100644 new mode 100755 similarity index 86% rename from zsh/update.zsh rename to zsh/bin/update index 5f1854b..15d1290 --- a/zsh/update.zsh +++ b/zsh/bin/update @@ -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() { case $UPDATE_CHECK in @@ -200,37 +210,46 @@ update-dotfiles() { echo "\033[32;1m=== Dotfiles updated in $formatted ===\033[0m" } -update() { +main() { - start=`date +%s` - echo "\033[32;1m=== Starting update ===\033[0m" + if [ $# -eq 0 ]; then - # Update the system - update-system + start=`date +%s` + echo "\033[32;1m=== Starting full update ===\033[0m" - # Update rust and rust packages - update-rust + # Update the system + update-system - # Update the dotfiles - update-dotfiles + # Update rust and rust packages + update-rust - seconds=$((`date +%s` - $start )) - formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` - echo "\033[32;1m=== Update finished in $formatted ===\033[0m" + # Update the dotfiles + update-dotfiles - 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 + } -# Spawn anonymous function -function() { - local format=`_date_format` - - if [ "$format" != "" ]; then - _check_date $format - fi -} +main $@ diff --git a/zsh/bin/vim-recover b/zsh/bin/vim-recover new file mode 100755 index 0000000..ba5c8b4 --- /dev/null +++ b/zsh/bin/vim-recover @@ -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 diff --git a/zsh/functions.zsh b/zsh/functions.zsh deleted file mode 100644 index dde85f2..0000000 --- a/zsh/functions.zsh +++ /dev/null @@ -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 - diff --git a/zsh/path.zsh b/zsh/path.zsh index ed91faa..2803d7d 100644 --- a/zsh/path.zsh +++ b/zsh/path.zsh @@ -2,6 +2,7 @@ export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH # The scripts path +export PATH=$DOTFILES/zsh/bin:$PATH if [ -d "$HOME/.scripts" ]; then export PATH=$HOME/.scripts:$PATH fi @@ -14,7 +15,10 @@ fi # Nvm path if [ -d $HOME/.nvm ]; then 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 # LD_LIBRARY_PATH: I don't know why there is this line here but I'm too scared diff --git a/zshrc b/zshrc index ed9cdca..7da7209 100644 --- a/zshrc +++ b/zshrc @@ -18,8 +18,9 @@ source $DOTFILES/zsh/config.zsh source $DOTFILES/zsh/path.zsh source $DOTFILES/zsh/exports.zsh source $DOTFILES/zsh/aliases.zsh -source $DOTFILES/zsh/functions.zsh if [ -f $DOTFILES/zsh/extraconfig.zsh ]; then source $DOTFILES/zsh/extraconfig.zsh fi + +update check