From 0ca03a69acdc441b8fd82b1157b0c2c77c9eba93 Mon Sep 17 00:00:00 2001 From: bretello Date: Fri, 14 Jul 2017 21:20:20 +0200 Subject: [PATCH 01/10] version 2.0 --- README.md | 29 +++--- aliases.sh | 35 +++++-- brethil_dotfile.sh | 64 +++++-------- check_for_update.sh | 63 ++++++++++++ colors.sh | 3 +- functions.sh | 177 +++++++++++++++++++--------------- install.sh | 227 ++++++++++++++++++++++++++------------------ 7 files changed, 362 insertions(+), 236 deletions(-) create mode 100755 check_for_update.sh diff --git a/README.md b/README.md index 26bebbb..16198ff 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ ## Description ## 1. brethil_dotfile.sh: main file sourced by ~/.bash_profile -2. aliases.sh: contains alias definitions (sources ~/.bash_aliases) -3. functions.sh: contains function definitions (sources ~/.bash_functions) +2. aliases.sh: contains alias definitions (sources ~/.dotfiles_aliases) +3. functions.sh: contains function definitions (sources ~/.dotfiles_functions) 4. colors.sh: contains color definitions 5. install.sh: run to install brethil's dotfiles @@ -15,30 +15,37 @@ Copy the dotfiles folder to the location where you want to keep it and then run $ cd dotfiles && bash install.sh Installs oh-my-zsh and sources aliases.sh, functions.sh and colors.sh, as well as installing -a a few utilities (see `install.sh`) +a a few utilities (see `install.sh`). ### Installed programs ### -0. oh-my-zsh (zsh config) +0. oh-my-zsh (zsh config framework, lots of plugins available at https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins) 1. byobu (wrapper/config for tmux, a screen multiplexer) -2. grc (generic colourizer, colours output of any command) +2. grc/ccze (output colorizers, color output of any command). Usage: + $ grc programname + $ programname | ccze 3. bmon (bandwidth monitor, shows graphs for bandwith usage) -3. rmate remote for Textmate (can be called with `mate`/`rmate`) +4. rmate remote for Textmate (can be called with `mate`/`rmate`) +5. mtr (my traceroute, traceroute+ping network utility) -### Available Commands ### +### Available Functions ### + +0. `cheat`, show cheat sheet for commands using cheat.sh (`cheat commandname`) 1. Quickly edit/reload profile (`esource`/`resource`) 2. `ramdisk` (only on OSX) create a RAM disk. Default size: 1GB ` ramdisk 4` creates a 4GB RAM disk 3. `color` to print colored text (see 3. in the Misc section): - color red "This will be printed in red" + color $Red "This will be printed in red" + color $Yellow "This will be printed in red" 4. `mecp` to copy files back to the machine from wich you are ssh-ing. For this to work an ssh tunnel with Remoteforward is needed: ssh -R 22:localhost:2222 YOURHOSTNAMEHERE or specify this in ~/.ssh/config: Host YOURHOSTNAMEHERE Remoteforward 2222 localhost:22 + This can be enabled in ~/.ssh/config globally for all hosts by uncommenting the relevant `Host * Remoteforward`. You might have to manually edit the username in the mecp definition in functions.sh if this is different between the two machines. mecp copies by default on the local machine on ~/Desktop/ 5. Many more. Type "list_functions" to list defined functions and a small description @@ -53,14 +60,14 @@ creates a 4GB RAM disk * (Optional: Compression, this should allow more responsive shells with slow connections, but will slow things down when copying large files. My suggestion is to have compression enabled on a by-host basis in `~/.ssh/config`) -3. brethil.zsh-theme, theme for oh-my-zsh, installed in ~/.oh-my-zsh/themes/ +3. brethil.zsh-theme, theme for oh-my-zsh, symlinked in ~/.oh-my-zsh/custom/themes 4. ~/.dotfiles_functions, ~/.dotfiles_aliases are sourced by this dotfiles, allowing for custom functions/aliases 5. useful_commands contains a list of useful commands (the first rule of the tautology club...) ### Misc ### -1. Colored output for `ls`/`grep`/`man` +1. Colored output for: `diff`, `configure`, `make`, `gcc`, `g`, `as`, `gas`, `ld`, `netstat`, `ping`, `traceroute`, `head`, `tail`, `dig`, `mount`, `ps`, `mtr` 2. Easy names for ANSI color escapes (Black, Red, Green, Yellow, Blue, Cyan, Purple, White, CLEAR), for example: `echo -e "${Green}This text will be green${CLEAR}"` -will result in green text. Use `$CLEAR` to clear previous escale sequences add B before the variable +will result in green text. Use `$CLEAR` to clear previous escape sequences add B before the variable (check colors.sh) name to use **bold** and U to underline (examples: $BRed, $UBlack for bold red and underlined black) diff --git a/aliases.sh b/aliases.sh index f3f58fc..090af77 100755 --- a/aliases.sh +++ b/aliases.sh @@ -36,11 +36,10 @@ fi alias bell='echo -en "\007"' alias grep="grep --color=auto" + ############## ## ls aliases ############ - - # ls -al, only show files that start with a dot alias lsdot="ls -al | awk '\$9 ~ /^\./ {print \$0}'" @@ -62,8 +61,8 @@ alias lsrt="ls -lrt | tail -10" #### New features ##################### -## List open connections (+c flag is to show command name with 15 characters (what the system provides)) -alias listconnections="lsof +c 15 -r -i TCP -i UDP" +## List open connections, TCP and UDP +alias listconnections="lsof -n -i TCP -i UDP" ## Stress (run stress &>/dev/null &) alias stress='yes >> /dev/null' @@ -76,12 +75,30 @@ alias mdiff="mate -t source.diff" # define ssh without controlmaster alias ssh1="ssh -o ControlMaster=no" -# Colorizing aliases (using grc) -alias ps="grc ps" -alias ping="grc ping" -alias traceroute="grc traceroute" -alias mtr="grc mtr" +# Some colorizing options for grc +GRC=`which grc` +if [ "$TERM" != dumb ] && [ -n "$GRC" ] +then + alias colourify="$GRC -es --colour=auto" + alias configure='colourify ./configure' + alias diff='colourify diff' + alias make='colourify make' + alias gcc='colourify gcc' + alias g++='colourify g++' + alias as='colourify as' + alias gas='colourify gas' + alias ld='colourify ld' + alias netstat='colourify netstat' + alias ping='colourify ping' + alias traceroute='colourify /usr/sbin/traceroute' + alias head='colourify head' + alias tail='colourify tail' + alias dig='colourify dig' + alias mount='colourify mount' + alias ps='colourify ps' + alias mtr='colourify mtr' +fi if [[ -f ~/.dotfiles_aliases ]]; then diff --git a/brethil_dotfile.sh b/brethil_dotfile.sh index 885ac69..d545a5a 100755 --- a/brethil_dotfile.sh +++ b/brethil_dotfile.sh @@ -1,57 +1,37 @@ -if [[ "$SHELL" == *"bash" ]]; then - alias resource="source $HOME/.bash_profile" - alias esource="mate -t source.shell $HOME/.bash_profile" -elif [[ "$SHELL" == *"/zsh" ]]; then - alias resource="source $HOME/.zshrc" - ## zsh plugins, these can be installed easily with zplug - #if [[ "$(uname)" == "Darwin" ]]; then - # plugins=(git common-aliases osx macports textmate anybar) - #else - # plugins=(git common-aliases) - #fi - - alias esource="mate -t source.shell $HOME/.zshrc" +# Check for update, set DISABLE_UPDATE_PROMPT=yes to disable the prompt and automatically update +env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $DOTFILES/check_for_update.sh + +# oh-my-zsh plugins (some of these have to be installed by running install.sh or install_zsh_plugins, found in install.sh) +shared_plugins=(git common-aliases fast-syntax-highlighting zsh-autosuggestions colored-man-pages zsh-navigation-tools zsh_reload cheat) + +uname=$(uname -a) +if [[ $uname == *"Darwin"* ]]; then + os_extra=(osx brew) +elif [[ $uname == *"ARCH"* ]]; then + os_extra=(archlinux) +elif [[ $uname == *"Debian"* ]]; then + os_extra=(debian) fi -alias dotedit="mate -t source.shell $DOTFILES/brethil_dotfile.sh" -alias funedit="mate -t source.shell $DOTFILES/functions.sh" -alias aledit="mate -t source.shell $DOTFILES/aliases.sh" +plugins=($shared_plugins $os_extra) + +alias resource="source $HOME/.zshrc" +alias dotedit="$EDITOR $DOTFILES/brethil_dotfile.sh" +alias funedit="$EDITOR $DOTFILES/functions.sh" +alias aledit="$EDITOR $DOTFILES/aliases.sh" # Extras functions_file=$DOTFILES/functions.sh # Function definitions aliases_file=$DOTFILES/aliases.sh # Aliases definitions colors_file=$DOTFILES/colors.sh # Colors definitions - # Source extras if [ -f $functions_file ]; then source $functions_file; fi if [ -f $aliases_file ]; then source $aliases_file; fi if [ -f $colors_file ]; then source $colors_file; fi -######################## -## Make prompt prettier -###################### -if [[ -e $BASH ]]; then - export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"' - ## This prompt only contains date, username and path, prints a red 'x' when a commands fails - #export PS1='[\t][:\w]$(if [[ $? != 0 ]]; then printf "[\[\e[31m\]✗\[\e[0m\]] "; else printf " "; fi)' - promptred="\[\033[1;31m\]" - promptgreen="\[\033[1;32m\]" - promptclear="\[\033[m\]" - export PS1="[\t][$promptred\h$promptclear][:$promtgreen\w$promptclear] " - - ### Other prompt choices: - ## This prompt includes includes host name - # export PS1='[\t][\h][\u:\w] ' - ## This prompt only includes username, date and path - #export PS1='[\t][\u:\w] ' -fi - -export EDITOR="mate -w" +export EDITOR="vim" ### SETUP PATHS #### -export PATH=$PATH:$HOME/bin/ -export PYTHONPATH=$PYTHONPATH:$HOME/python/:$HOME/bin - -## One can also use most pager instead of less to visualize man pages -#export PAGER="most" +export PATH=$PATH:$HOME/bin +#export PYTHONPATH=$PYTHONPATH:$HOME/python/:$HOME/bin \ No newline at end of file diff --git a/check_for_update.sh b/check_for_update.sh new file mode 100755 index 0000000..3894c23 --- /dev/null +++ b/check_for_update.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env zsh +# +# brethil, brutally copied form https://github.com/robbyrussell/oh-my-zsh/blob/master/tools/check_for_upgrade.sh +# 14 July 2017 + +zmodload zsh/datetime + +function _current_epoch() { + echo $(( $EPOCHSECONDS / 60 / 60 / 24 )) +} + +function _update_dotfiles_update() { + echo "LAST_EPOCH=$(_current_epoch)" >! ~/.dotfiles-update +} + +function _upgrade_dotfiles() { + (cd $DOTFILES; git pull) + # update the zsh file + _update_dotfiles_update +} + +epoch_target=$UPDATE_ZSH_DAYS +if [[ -z "$epoch_target" ]]; then + # Default to old behavior + epoch_target=13 +fi + +# Cancel upgrade if the current user doesn't have write permissions for the +# oh-my-zsh directory. +[[ -w "$ZSH" ]] || return 0 + +# Cancel upgrade if git is unavailable on the system +whence git >/dev/null || return 0 + +if mkdir "$DOTFILES/log/update.lock" 2>/dev/null; then + if [ -f ~/.dotfiles-update ]; then + . ~/.dotfiles-update + + if [[ -z "$LAST_EPOCH" ]]; then + _update_dotfiles_update && return 0; + fi + + epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) + if [ $epoch_diff -gt $epoch_target ]; then + if [ "$DISABLE_UPDATE_PROMPT" = "true" ]; then + _upgrade_dotfiles + else + echo "[brethil dotfiles] Would you like to check for updates? [Y/n]: \c" + read line + if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then + _upgrade_dotfiles + else + _update_dotfiles_update + fi + fi + fi + else + # create the dotfiles file + _update_dotfiles_update + fi + + rmdir $DOTFILES/log/update.lock +fi diff --git a/colors.sh b/colors.sh index 3584cc9..dd8de95 100755 --- a/colors.sh +++ b/colors.sh @@ -73,14 +73,13 @@ On_ICyan='\e[0;106m' # Cyan On_IWhite='\e[0;107m' # White - # ANSI COLOR ESCAPES 2 ## Clear all previous sequences # Bold text BOLD="\e[1m" # Colors: Black, Blue, Green, Cyan, Red, Purple, Brown, LightGray BLACK="\e[30m"; BLUE="\e[34m"; GREEN="\e[32m"; CYAN="\e[36m"; -RED="\e\[31m"; PURPLE="\e[35m"; BROWN="\e[33m"; LIGHTGRAY="\e[37m"; +RED="\e[31m"; PURPLE="\e[35m"; BROWN="\e[33m"; LIGHTGRAY="\e[37m"; DARKGRAY="\e[30m"; LIGHTBLUE="\e[34m"; LIGHTGREEN="\e[32m"; LIGHTCYAN="\e[36m"; LIGHTRED="\e[31m"; LIGHTPURPLE="\e[35m"; YELLOW="\e[33m"; WHITE="\e[37m" diff --git a/functions.sh b/functions.sh index d23c1e8..37876dd 100755 --- a/functions.sh +++ b/functions.sh @@ -1,31 +1,24 @@ ########################### #### Function Definitions # ########################### +## Selfupdate +function dotfiles_selfupdate +{ + (cd $DOTFILES; git pull) +} - +## get cheat sheets for commands from cheat.sh. Usage: cheat commandname +function cheat +{ + curl cheat.sh/$1 +} ## Simple calculator. Usage: calc 1+1, calc 5/7, calc "sqrt(2)" -function calc { - awk "BEGIN { print "$*" }" -} - - -## Open Man in separate (good looking) window -function nman +function calc { - if [ $# -eq 1 ] ; - then open x-man-page://$1 ; - elif [ $# -eq 2 ] ; - then open x-man-page://$1/$2 ; - fi + awk "BEGIN { print "$*" }" } -## Open a pdf version of the man in Preview -function man2pdf -{ - man -t "$1" | open -f -a Preview -} - -## Make new directory and cd to that directory +## Make new directory and cd to that directory. Usage: mcd newfolder function mcd { mkdir -p $1 @@ -47,36 +40,38 @@ function color } -## These functions return a colored version of the input string +## These functions return a colored version of the input string. Usage: red "string" function red { - echo -e "$RED$@$CLEAR" + echo -e "$Red$@$CLEAR" } -function green { - echo -e "$GREEN$@$CLEAR" +function green +{ + echo -e "$Green$@$CLEAR" } - function blue { - echo -e "$BLUE$1$CLEAR" + function blue + { + echo -e "$Blue@$CLEAR" } ## Flashes the screen until user presses a key function flasher { - while true; do printf "\e[?5h\007"; sleep 0.25; printf "\e[?5l"; read -s -n1 -t1 && break; done; + while true; do printf "\e[?5h\007"; sleep 0.25; printf "\e[?5l"; read -s -n -t1 && break; done; } ## Beep until user presses a key function beeper { - while true; do printf "\e[?5h\007"; sleep 0.25; printf "\e[?5l"; read -s -n1 -t1 && break; done; + while true; do printf "\e[?5h\007"; sleep 0.25; printf "\e[?5l"; read -s -n -t1 && break; done; } -## Search youtube for string ($1) and play video +## Search youtube for string ($1) and play video (uses mplayer) function pyt { echo 'https://www.youtube.com/results?search_query='"$(sed 's/ /%20/g' <<< $(tr '\' '+' <<< "$@"))"; id=$(curl -s 'https://www.youtube.com/results?search_query='"$(sed 's/ /%20/g' <<< $(tr '\' '+' <<< "$@"))" | grep -om3 '"[[:alnum:]]\{11\}"' | awk NR==3 | tr -d \"); url='https://www.youtube.com/watch?v='"$id"; echo -e "URL:\t$url"; youtube-dl -q $url -o - | mplayer -vo corevideo -really-quiet /dev/fd/3 3<&0 in clipboard" } else - function termbin { + ## Copy output of previous command to termbin.com (command line pastebin) + function termbin + { nc termbin 9999 } fi +## List defined functions in $DOTFILES/functions.sh +function list_functions +{ + cat $DOTFILES/functions.sh | grep --color=no -A 1 '^##' | sed -E 's/function (.*)/\1/g' +} + + ########################### ## MAC SPECIFIC # ########################### if [[ "$(uname)" == "Darwin" ]]; then - ## Create a RAM disk. Default size 1GB. If supplied, first argument defines the RAM disk size in GB - function ramdisk { - if [[ -e $1 ]]; - then - sizeingb=$1 - else - sizeingb=1 - fi - - # Numsectors is size in bytes / 512 (sector size in bytes) - name='RAM_disk' - sizeinbytes=$(($sizeingb*1000**3)) - NUMSECTORS=$(($sizeinbytes/512)) - mydev=$(hdiutil attach -nomount ram://$NUMSECTORS ) - # strip whitespace (hdiutil outputs a lot of spaces/tabs along with the device name) - mydev=$(echo "$mydev"| xargs echo) - newfs_hfs $mydev - mkdir -p "/tmp/$name" - mount -t hfs $mydev "/tmp/$name" - echo "RAM Disk mounted: /tmp/$name" - echo "To eject (destroy) RAM disk, use:" - echo " $ diskutil eject $mydev" - } - - # Anybar support https://github.com/tonsky/AnyBar - function anybar { echo -n $1 | nc -4u -w0 localhost ${2:-1738}; } - -fi +## Create a RAM disk. Default size 1GB. If supplied, first argument defines the RAM disk size in GB +function ramdisk +{ + if [[ -e $1 ]]; + then + sizeingb=$1 + else + sizeingb=1 + fi + + # Numsectors is size in bytes / 512 (sector size in bytes) + name='RAM_disk' + sizeinbytes=$(($sizeingb*1000**3)) + NUMSECTORS=$(($sizeinbytes/512)) + mydev=$(hdiutil attach -nomount ram://$NUMSECTORS ) + # strip whitespace (hdiutil outputs a lot of spaces/tabs along with the device name) + mydev=$(echo "$mydev"| xargs echo) + newfs_hfs $mydev + mkdir -p "/tmp/$name" + mount -t hfs $mydev "/tmp/$name" + echo "RAM Disk mounted: /tmp/$name" + echo "To eject (destroy) RAM disk, use:" + echo " $ diskutil eject $mydev" +} + +## Anybar support https://github.com/tonsky/AnyBar +function anybar +{ + echo -n $1 | nc -4u -w0 localhost ${2:-1738}; +} + +## Open a pdf version of the man in Preview +function man2pdf +{ + man -t "$1" | open -f -a Preview +} + +## Open Man in separate (different-looking) window +function nman +{ + if [ $# -eq 1 ] ; + then open x-man-page://$1 ; + elif [ $# -eq 2 ] ; + then open x-man-page://$1/$2 ; + fi +} +fi # end of mac-specific functions if [[ -f ~/.dotfiles_functions ]]; then - source ~/.dotfiles_functions + source ~/.dotfiles_functions fi diff --git a/install.sh b/install.sh index 8428971..2371008 100755 --- a/install.sh +++ b/install.sh @@ -5,38 +5,45 @@ # Get the location for the dotfiles DOTFILES=$PWD -echo -e "\n\n# Beginning of brethil's dotfiles:" >> ~/.zshrc -echo "DOTFILES=$DOTFILES" >> ~/.zshrc -echo "source \$DOTFILES/brethil_dotfile.sh" >> ~/.zshrc - +ZSHTMP="$HOME/.zshrctmp" +echo -e "\n\n# brethil's dotfiles:" >> $ZSHTMP +echo "DOTFILES=$DOTFILES" >> $ZSHTMP +echo "source \$DOTFILES/brethil_dotfile.sh" >> $ZSHTMP +echo -e "# End of brethil's dotfiles\n\n" function install_rmate { - ## Ruby version: - #curl -Lo ~/bin/rmate https://raw.github.com/textmate/rmate/master/bin/rmate - ## Python version: - echo "Installing rmate (python)..." + # Install python version of the textmate rmate remote (from github) if [[ $(whoami) == "root" ]]; then destpath="/usr/bin" else destpath="$HOME/bin" fi - curl -sL https://raw.githubusercontent.com/sclukey/rmate-python/master/bin/rmate >> $destpath/rmate - chmod a+x $destpath/rmate - ln -s $destpath/rmate $destpath/mate || "Could not create symbolic link to $destpath/mate (already exists?)" - echo "Installed rmate (and mate symlink) in $destpath" + if [[ -f $destpath/rmate ]]; then + echo "rmate already exists: not installed" + return -1 + else + curl -sL https://raw.githubusercontent.com/sclukey/rmate-python/master/bin/rmate > $destpath/rmate + chmod a+x $destpath/rmate + ln -s $destpath/rmate $destpath/mate || "Could not create symbolic link to $destpath/mate (already exists?)" + echo "Installed rmate (and mate symlink) in $destpath" + return 0 + fi } - function install_vimrc { - git clone https://github.com/amix/vimrc.git $HOME/.vim_runtime - sh $HOME/.vim_runtime/install_awesome_vimrc.sh + # Install vimrc from github.com/amix/vimrc + git clone https://github.com/amix/vimrc.git $HOME/.vim_runtime && sh $HOME/.vim_runtime/install_awesome_vimrc.sh || return -1 } function install_zsh_plugins { - # Install fast-syntax-highlighting zsh-autosuggestions + # Install fast-syntax-highlighting (git: zdharma), zsh-autosuggestions (git:zsh-users) ZSH_PLUGINS="$HOME/.oh-my-zsh/custom/plugins" - git clone https://github.com/zdharma/fast-syntax-highlighting.git ${ZSH_PLUGINS}/fast-syntax-highlighting - git clone git://github.com/zsh-users/zsh-autosuggestions ${ZSH_PLUGINS}/zsh-autosuggestions - + git clone https://github.com/zdharma/fast-syntax-highlighting.git ${ZSH_PLUGINS}/fast-syntax-highlighting || error=true + git clone git://github.com/zsh-users/zsh-autosuggestions ${ZSH_PLUGINS}/zsh-autosuggestions || error=true + if [[ $error ]]; then + return -1 + else + return 0 + fi } # Add an ssh config file with: @@ -47,14 +54,22 @@ function create_ssh_config { ssh_config="$HOME/.ssh/config" - if [ ! -d $HOME/.ssh/id_rsa ]; then - ssh-keygen -t rsa -b 4096 + if [ ! -f $HOME/.ssh/id_rsa ]; then + echo "Creating ssh key (4096bit)..." + + echo "Enter ssh-key comment (leave empty for default: user@host)" + read comment + if [[ $comment ]]; + ssh-keygen -t rsa -b 4096 -C $comment + else + ssh-keygen -t rsa -b 4096 + done + # fix permissions chmod 0700 "$HOME/.ssh" fi if [[ -f $ssh_config ]]; then - while [ "$modifyssh" != "y" ] && [ "$modifyssh" != "n" ] - do + until [[ $modifyssh == "y" ]] or [[ $modifyssh == "n" ]]; do echo "Do you want to modify the existing ssh config? (New values will be appended) (y/n)" read modifyssh done @@ -62,118 +77,141 @@ function create_ssh_config { if [[ "$modifyssh" != "n" ]] then - echo "# brethil's dotfiles setup start" >> $ssh_config - echo 'TCPKeepAlive=yes' >> $ssh_config - echo 'ServerAliveCountMax=6' >> $ssh_config + echo "# brethil's dotfiles setup start" >> $ssh_config + echo 'TCPKeepAlive=yes' >> $ssh_config + echo 'ServerAliveCountMax=6' >> $ssh_config - ## Compression will slow things down when copying large files, but improve - ## speed if only using a shell, my reccommendation is to enable it on a by-host - ## basis in ~/.ssh/config - #echo ' Compression=yes' >> $ssh_config + echo "## Uncomment to enable compression for all ssh sessions" >> $ssh_config + echo '#Compression=yes' >> $ssh_config - #echo 'ControlMaster auto' >> $ssh_config - #echo 'ControlPath /tmp/%r@%h:%p' >> $ssh_config - #echo 'ControlPersist yes' >> $ssh_config - echo 'Host *' >> $ssh_config - echo 'ServerAliveInterval 300' >> $ssh_config - echo '# end of brethil dotfiles setup #' >> $ssh_config + echo '## Uncomment the following to enable ssh ControlMaster and ssh session persistence' >> $ssh_config + echo '#ControlMaster auto' >> $ssh_config + echo '#ControlPath /tmp/%r@%h:%p' >> $ssh_config + echo '#ControlPersist yes' >> $ssh_config + echo 'Host *' >> $ssh_config + echo 'ServerAliveInterval 300' >> $ssh_config + echo '## Enable the following if you want to use the rmate textmate remote' >> $ssh_config + echo "#Host *" >> $ssh_config + echo "#RemoteForward 52698 localhost:52698" >> $ssh_config + echo '## Enable the following if you want to use a reverse ssh tunnel to use mecp command on remote hosts' >> $ssh_config + echo "Host *" >> $ssh_config + echo "Remoteforward 2222 localhost:22" >> $ssh_config + echo '# end of brethil dotfiles setup #' >> $ssh_config - ## Enable the following if you want to use the rmate textmate remote - #echo "Host *" >> $ssh_config - #echo "RemoteForward 52698 localhost:52698" >> $ssh_config - ## Enable the following if you want to use a reverse ssh tunnel (mecp) - #echo "Host *" >> $ssh_config - #echo "Remoteforward 2222 localhost:22" >> $ssh_config - - # - echo ".ssh folder configured, enabled ControlMaster for all connections." - echo "Compression disabled, enable by uncommenting 'Compression' in ~/.ssh/config" - echo "Remote forwarding port 52698->52698 (Textmate) and port 2222->22 (mecp) for all hosts." + echo ".ssh/ssh_config configured check it to enable custom options:" + echo "- Compression" + echo "- Remote forwarding port 52698->52698 (Textmate rmate remote)" + echo "- Remote forwarding remote:2222->localhost:22 (mecp)" else echo "Did not modify $ssh_config." fi echo "# End of ssh config." } -# Run after first copying to a remote machine +# First setup function brethil_dotfiles_setup { - bin="$HOME/bin/" - #python="$HOME/python" + bin="$HOME/bin" projects="$HOME/projects" git="$HOME/git" - mkdir -p "$bin" - mkdir -p "$projects" - mkdir -p "$git" - - - echo "Created dirs $bin, $projects, $git" - - + mkdir -p "$bin" "$projects" "$git" && echo "Created dirs $bin, $projects, $git" + # Install packages # zsh - # byobu: configuration/wrapper for tmux # grc: generic colourizer, colors output of any command + # ccze: similar to the above + # byobu: configuration/wrapper for tmux # bmon: bandwidth monitor, monitors bandwith usage, shows graph # mtr: mytraceroute, traceroute tool # pv: pipe view, monitor the progress of data through a pipe # byobu: tmux wrapper - packages="zsh git grc bmon mtr pv tmux byobu" + packages="zsh git grc ccze bmon mtr pv tmux byobu" - # Check if running as root, if not, quit. - if [[ ! $(id -g) == 0 ]]; then - echo "This has to be run as root to install new software from the repos. Quitting..." - exit 0 + # Check if running as root, if try using sudo to install packages. + # If sudo is not installed, launch a shell to try and install it + if [[ $(id -u) != 0 ]]; then + if [[ ! -f $(which sudo) ]] ; then + unset yn + until [[ $yn == "y" || $yn == "n" ]]; do + echo "Cannot install new packages without root access. Do you want to try to manually install sudo? (yn) " + read yn + done + if [[ $yn == "y" ]]; then + echo "Launching an interactive shell. Type exit after installing sudo." + /bin/bash + else + echo "Quitting." + exit 0 + fi + else [[ -f $(which sudo) ]]; then + sudo="sudo " + fi fi if [[ $(which apt-get ) ]]; then - install_command="apt-get install" + install_command="${sudo}apt-get install" elif [[ $(which pacman) ]]; then - install_command="pacman -Sy" + install_command="${sudo}pacman -Sy" elif [[ $(which yum) ]]; then - install_command="yum" + install_command="${sudo}yum" elif [[ $(which port) ]]; then - install_command="port install" + install_command="${sudo}port install" elif [[ $(which brew) ]]; then - install_command="brew install" + install_command="${sudo}brew install" else - echo "Could not install required packages" - error=true + echo "I do not know how to install the required packages. Quitting." + exit 0 fi - if [[ ! $error ]]; then - $install_command $packages - # Install oh-my-zsh - echo "Installing oh-my-zsh..." - sh -c "$(curl -sL zsh.dioporc.one)" - - ## Fix scrolling in byobu + $install_command $packages + # Install oh-my-zsh + echo "Installing oh-my-zsh..." + sh -c "$(curl -sL zsh.dioporc.one)" + + # oh-my-zsh's zshrc has been installed, prepend the dotfiles setup to it + cat $HOME/.zshrc >> $ZSHTMP + mv $ZSHTMP $HOME/.zshrc + + # Increase history size + echo "export HISTSIZE=100000" >> $HOME/.zshrc + + ## Fix scrolling in byobu + if [[ $(uname) == "Darwin" ]]; then + sed -i '' 's/set -g terminal-overrides/#set -g terminal-overrides/' /usr/share/byobu/profiles/tmux + else sed -i 's/set -g terminal-overrides/#set -g terminal-overrides/' /usr/share/byobu/profiles/tmux - - echo "bind m setw -g mode-mouse on" >> ~/.tmux.conf - echo "bind M setw -g mode-mouse off" >> ~/.tmux.conf fi + # Set m and M to enable/disable mouse mode in tmux/byobu + echo 'bind-key m source $BYOBU_PREFIX/share/byobu/keybindings/mouse.tmux.enable \; display-message "Mouse: ON"' >> ~/.tmux.conf + echo 'bind-key M source $BYOBU_PREFIX/share/byobu/keybindings/mouse.tmux.disable \; display-message "Mouse: Off"' >> ~/.tmux.conf + # Install the rmate client for textmate - install_rmate + inhstall_rmate && echo "Installed rmate Textmate remote "|| echo "Failed to install rmate Textmate remote" # Install vim awesomerc (git amix/vimrc) - install_vimrc + install_vimrc && echo "Installed vim awesome rc" || echo "Failed to install vim awesome rc" # Create ssh config create_ssh_config # Install new zsh plugins in $ZSH/custom/plugins/ - install_zsh_plugins + install_zsh_plugins && echo "Installed custom zsh plugins in $ZSH/custom/plugins/" || echo "Failed to install custom zsh plugins" - # Comment enabled plugins in ~/.zshrc - sed -e '/plugins=\(\.*\)/ s/^#*/#/' -i $HOME/.zshrc - # Enable these plugins: - plugins="plugins=(git common-aliases fast-syntax-highlighting zsh-autosuggestions colored-man-pages)" - echo $plugins >> $HOME/.zshrc + # Source the plugins defined in brethil_dotfile.sh ($plugins) + if [[ $(uname) == "Darwin" ]]; then # MacOS has a different syntax for sed + sed -i "" -e 's/plugins=.*/plugins=\( $plugins \)/' $HOME/.zshrc + else + sed -i -e 's/plugins=.*/plugins=\( $plugins \)/' $HOME/.zshrc + fi - # Copy brethil.zsh-theme + # Symlink brethil.zsh-theme ln -s $DOTFILES/brethil.zsh-theme $HOME/.oh-my-zsh/themes/ + # Set brethil theme - sed -i 's/ZSH_THEME=".*"/ZSH_THEME="brethil"/' $HOME/.zshrc + if [[ $(uname) == "Darwin" ]]; then # MacOS has a different syntax for sed + sed -i '' 's/ZSH_THEME=".*"/ZSH_THEME="brethil"/' $HOME/.zshrc + else + sed -i 's/ZSH_THEME=".*"/ZSH_THEME="brethil"/' $HOME/.zshrc + fi } @@ -181,9 +219,8 @@ function brethil_dotfiles_setup { # Setup brethil_dotfiles_setup -echo "Functions are defined in $DOTFILES/functions.sh (you can add extra functions in ~/.dotfiles_functions)" -echo "Aliases are defined in $DOTFILES/aliases.sh (you can add extra aliases in ~/.dotfiles_aliases)" +echo "Functions definitions in $DOTFILES/functions.sh (you can add your own functions in ~/.dotfiles_functions)" +echo "Aliases definitions in $DOTFILES/aliases.sh (you can add your own aliases in ~/.dotfiles_aliases)" echo "Colors are defined in $DOTFILES/colors.sh" -echo "These 3 files are sourced by $DOTFILES/brethil_dotfile.sh, which is in turn sourced by ~/.zshrc" -echo "Type . ~/.zshrc to source the new dotfiles, or simply launch another shell." +echo "Type . ~/.zshrc to source the new dotfiles, or simply launch another shell. )" From c1d1b3177831645a76da8bdacc98f18c8963b1f9 Mon Sep 17 00:00:00 2001 From: bretello Date: Mon, 17 Jul 2017 01:28:35 +0200 Subject: [PATCH 02/10] Added brethil-mobile.zsh-theme. Minor bugfixes --- README.md | 14 +++++++++----- aliases.sh | 10 +++------- brethil-minimal.zsh-theme | 8 ++++++++ brethil_dotfile.sh | 2 +- functions.sh | 17 +++++++---------- install.sh | 13 ++++++++----- 6 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 brethil-minimal.zsh-theme diff --git a/README.md b/README.md index 16198ff..ed5841c 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,10 @@ Copy the dotfiles folder to the location where you want to keep it and then run Installs oh-my-zsh and sources aliases.sh, functions.sh and colors.sh, as well as installing a a few utilities (see `install.sh`). -### Installed programs ### +### Installed ### 0. oh-my-zsh (zsh config framework, lots of plugins available at https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins) + Two zsh themes: brethil and brethil-minimal. 1. byobu (wrapper/config for tmux, a screen multiplexer) 2. grc/ccze (output colorizers, color output of any command). Usage: $ grc programname @@ -28,7 +29,6 @@ a a few utilities (see `install.sh`). 4. rmate remote for Textmate (can be called with `mate`/`rmate`) 5. mtr (my traceroute, traceroute+ping network utility) - ### Available Functions ### 0. `cheat`, show cheat sheet for commands using cheat.sh (`cheat commandname`) @@ -52,7 +52,7 @@ creates a 4GB RAM disk ### Files/Folders ### -1. `~/bin`, `~/python`, `~/projects` folders +1. `~/bin`, `~/git`, `~/projects` folders 2. ssh config (`~/.ssh/config`): * Create ssh keys if not defined already * Keep connections alive by increasing timeout time @@ -60,14 +60,18 @@ creates a 4GB RAM disk * (Optional: Compression, this should allow more responsive shells with slow connections, but will slow things down when copying large files. My suggestion is to have compression enabled on a by-host basis in `~/.ssh/config`) -3. brethil.zsh-theme, theme for oh-my-zsh, symlinked in ~/.oh-my-zsh/custom/themes +3. brethil.zsh-theme, brethil-minimal.zsh-themes, themes for oh-my-zsh, symlinked in `$ZSH/custom/themes` ($ZSH=~/.oh-my-zsh) 4. ~/.dotfiles_functions, ~/.dotfiles_aliases are sourced by this dotfiles, allowing for custom functions/aliases 5. useful_commands contains a list of useful commands (the first rule of the tautology club...) + ### Misc ### -1. Colored output for: `diff`, `configure`, `make`, `gcc`, `g`, `as`, `gas`, `ld`, `netstat`, `ping`, `traceroute`, `head`, `tail`, `dig`, `mount`, `ps`, `mtr` +1. Colored output (via `grc`) for: `diff`, `configure`, `make`, `gcc`, `g`, `as`, `gas`, `ld`, `netstat`, `ping`, `traceroute`, `head`, `tail`, `dig`, `mount`, `ps`, `mtr` 2. Easy names for ANSI color escapes (Black, Red, Green, Yellow, Blue, Cyan, Purple, White, CLEAR), for example: `echo -e "${Green}This text will be green${CLEAR}"` will result in green text. Use `$CLEAR` to clear previous escape sequences add B before the variable (check colors.sh) name to use **bold** and U to underline (examples: $BRed, $UBlack for bold red and underlined black) +3. Type `esc` twice to add `sudo` before the current command +4. Autoupdate script running every two weeks, autoupdate function: dotfiles_selfupdate (or `git pull` from `$DOTFILES` folder) +5. \ No newline at end of file diff --git a/aliases.sh b/aliases.sh index 090af77..ca8b938 100755 --- a/aliases.sh +++ b/aliases.sh @@ -57,10 +57,6 @@ alias upcd='. upcd.sh' ## Show the last 10 modified files alias lsrt="ls -lrt | tail -10" -##################### -#### New features -##################### - ## List open connections, TCP and UDP alias listconnections="lsof -n -i TCP -i UDP" ## Stress (run stress &>/dev/null &) @@ -78,9 +74,9 @@ alias ssh1="ssh -o ControlMaster=no" # Some colorizing options for grc GRC=`which grc` -if [ "$TERM" != dumb ] && [ -n "$GRC" ] -then - alias colourify="$GRC -es --colour=auto" +if [ "$TERM" != dumb ] && [ -n "$GRC" ]; then + #alias colourify="$GRC -es --colour=auto" + alias colourify="$GRC --colour=auto" alias configure='colourify ./configure' alias diff='colourify diff' alias make='colourify make' diff --git a/brethil-minimal.zsh-theme b/brethil-minimal.zsh-theme new file mode 100644 index 0000000..2dc563f --- /dev/null +++ b/brethil-minimal.zsh-theme @@ -0,0 +1,8 @@ +ret_status="%(?:%{$fg_bold[green]%}➜%{$reset_color%}:%{$fg[red]%}➜%{$reset_color%})" +user="%(#:[root]:)" +PROMPT='%{$fg[red]%}${user}%{$reset_color%}[:%{$fg[green]%}%c%{$reset_color%}]$(git_prompt_info) ${ret_status} ' + +ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[yellow]%}git:(" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[yellow]%})%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[white]%} %{$fg[red]%}✗%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[white]%} %{$fg[green]%}√%{$reset_color%}" \ No newline at end of file diff --git a/brethil_dotfile.sh b/brethil_dotfile.sh index d545a5a..2104b67 100755 --- a/brethil_dotfile.sh +++ b/brethil_dotfile.sh @@ -2,7 +2,7 @@ env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $DOTFILES/check_for_update.sh # oh-my-zsh plugins (some of these have to be installed by running install.sh or install_zsh_plugins, found in install.sh) -shared_plugins=(git common-aliases fast-syntax-highlighting zsh-autosuggestions colored-man-pages zsh-navigation-tools zsh_reload cheat) +shared_plugins=(git brew common-aliases fast-syntax-highlighting zsh-autosuggestions colored-man-pages zsh-navigation-tools zsh_reload sudo alias-tips) uname=$(uname -a) if [[ $uname == *"Darwin"* ]]; then diff --git a/functions.sh b/functions.sh index 37876dd..83cdc28 100755 --- a/functions.sh +++ b/functions.sh @@ -157,13 +157,11 @@ function list_functions ## MAC SPECIFIC # ########################### -if [[ "$(uname)" == "Darwin" ]]; -then +if [[ "$(uname)" == "Darwin" ]]; then ## Create a RAM disk. Default size 1GB. If supplied, first argument defines the RAM disk size in GB function ramdisk { - if [[ -e $1 ]]; - then + if [[ -e $1 ]]; then sizeingb=$1 else sizeingb=1 @@ -199,16 +197,15 @@ function man2pdf ## Open Man in separate (different-looking) window function nman { - if [ $# -eq 1 ] ; - then open x-man-page://$1 ; - elif [ $# -eq 2 ] ; - then open x-man-page://$1/$2 ; + if [ $# -eq 1 ] ; then + open x-man-page://$1 ; + elif [ $# -eq 2 ] ; then + open x-man-page://$1/$2 ; fi } fi # end of mac-specific functions -if [[ -f ~/.dotfiles_functions ]]; -then +if [[ -f ~/.dotfiles_functions ]]; then source ~/.dotfiles_functions fi diff --git a/install.sh b/install.sh index 2371008..731440f 100755 --- a/install.sh +++ b/install.sh @@ -59,17 +59,17 @@ function create_ssh_config { echo "Enter ssh-key comment (leave empty for default: user@host)" read comment - if [[ $comment ]]; + if [[ $comment ]]; then ssh-keygen -t rsa -b 4096 -C $comment else ssh-keygen -t rsa -b 4096 - done + fi # fix permissions chmod 0700 "$HOME/.ssh" fi if [[ -f $ssh_config ]]; then - until [[ $modifyssh == "y" ]] or [[ $modifyssh == "n" ]]; do + until [[ $modifyssh == "y" || $modifyssh == "n" ]]; do echo "Do you want to modify the existing ssh config? (New values will be appended) (y/n)" read modifyssh done @@ -137,12 +137,13 @@ function brethil_dotfiles_setup { done if [[ $yn == "y" ]]; then echo "Launching an interactive shell. Type exit after installing sudo." - /bin/bash + # Launch bash + $(which bash) else echo "Quitting." exit 0 fi - else [[ -f $(which sudo) ]]; then + elif [[ -f $(which sudo) ]]; then sudo="sudo " fi fi @@ -205,6 +206,8 @@ function brethil_dotfiles_setup { # Symlink brethil.zsh-theme ln -s $DOTFILES/brethil.zsh-theme $HOME/.oh-my-zsh/themes/ + # Symlink brethil-minimal.zsh-theme + ln -s $DOTFILES/brethil-minimal.zsh-theme $HOME/.oh-my-zsh/themes/ # Set brethil theme if [[ $(uname) == "Darwin" ]]; then # MacOS has a different syntax for sed From 6988e525eb767b5eae5ea8a63e4a98cb53e0d6a1 Mon Sep 17 00:00:00 2001 From: bretello Date: Mon, 17 Jul 2017 01:59:38 +0200 Subject: [PATCH 03/10] Updated selfupdate function to include custom oh-my-zsh plugins --- functions.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/functions.sh b/functions.sh index 83cdc28..c8df6bd 100755 --- a/functions.sh +++ b/functions.sh @@ -4,7 +4,18 @@ ## Selfupdate function dotfiles_selfupdate { + # Pull dotfiles (cd $DOTFILES; git pull) + WD=$PWD + # Update all git repos in $ZSH/custom/plugins + cd $ZSH/custom/plugins + for folder in $(ls); do + if [[ -f "$folder/.git" ]]; then + (cd $folder; git pull) + fi + done + # go back to previous working directory + cd $WD } ## get cheat sheets for commands from cheat.sh. Usage: cheat commandname From 46177a425c5594a58a708bcc082aeee49f8ba52f Mon Sep 17 00:00:00 2001 From: bretello Date: Mon, 17 Jul 2017 02:00:15 +0200 Subject: [PATCH 04/10] Minor fixes/improvements --- README.md | 2 +- aliases.sh | 3 +-- brethil_dotfile.sh | 26 ++++++++++++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ed5841c..a38731a 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ creates a 4GB RAM disk This can be enabled in ~/.ssh/config globally for all hosts by uncommenting the relevant `Host * Remoteforward`. You might have to manually edit the username in the mecp definition in functions.sh if this is different between the two machines. mecp copies by default on the local machine on ~/Desktop/ - 5. Many more. Type "list_functions" to list defined functions and a small description +5. Many more. Type "list_functions" to list defined functions and a small description ### Files/Folders ### diff --git a/aliases.sh b/aliases.sh index ca8b938..991f90e 100755 --- a/aliases.sh +++ b/aliases.sh @@ -2,7 +2,6 @@ #### ALIAS # ########################### - #### #### Easier life (MAC SPECIFIC) #### @@ -73,7 +72,7 @@ alias ssh1="ssh -o ControlMaster=no" # Some colorizing options for grc -GRC=`which grc` +GRC=$(which grc) if [ "$TERM" != dumb ] && [ -n "$GRC" ]; then #alias colourify="$GRC -es --colour=auto" alias colourify="$GRC --colour=auto" diff --git a/brethil_dotfile.sh b/brethil_dotfile.sh index 2104b67..6b1e590 100755 --- a/brethil_dotfile.sh +++ b/brethil_dotfile.sh @@ -6,19 +6,31 @@ shared_plugins=(git brew common-aliases fast-syntax-highlighting zsh-autosuggest uname=$(uname -a) if [[ $uname == *"Darwin"* ]]; then - os_extra=(osx brew) + if [[ $(which brew) ]]; then + os_extra=(osx brew) + elif [[ $(which port)]]; then + os_extra=(osx macports) + else + os_extra=(osx) + fi elif [[ $uname == *"ARCH"* ]]; then os_extra=(archlinux) elif [[ $uname == *"Debian"* ]]; then os_extra=(debian) fi + +# https://www.xkcd.com/378/ +export EDITOR="vim" + plugins=($shared_plugins $os_extra) +alias esource="$EDITOR $HOME/.zshrc" alias resource="source $HOME/.zshrc" alias dotedit="$EDITOR $DOTFILES/brethil_dotfile.sh" -alias funedit="$EDITOR $DOTFILES/functions.sh" -alias aledit="$EDITOR $DOTFILES/aliases.sh" +# Custom definitions files +alias funedit="$EDITOR ~/.dotfiles_functions.sh" +alias aledit="$EDITOR ~/.dotfiles_aliases.sh" # Extras functions_file=$DOTFILES/functions.sh # Function definitions @@ -26,11 +38,9 @@ aliases_file=$DOTFILES/aliases.sh # Aliases definitions colors_file=$DOTFILES/colors.sh # Colors definitions # Source extras -if [ -f $functions_file ]; then source $functions_file; fi -if [ -f $aliases_file ]; then source $aliases_file; fi -if [ -f $colors_file ]; then source $colors_file; fi - -export EDITOR="vim" +if [ -f $functions_file ]; then source $functions_file; else echo "[brethil-dotfiles] Couldn't load functions: $functions_file"; fi +if [ -f $aliases_file ]; then source $aliases_file; else echo "[brethil-dotfiles] Couldn't load aliases: $aliases_file"; fi +if [ -f $colors_file ]; then source $colors_file; else echo "[brethil-dotfiles] Couldn't load colors: $colors_file";fi ### SETUP PATHS #### export PATH=$PATH:$HOME/bin From aacccf60a96fdb6ec12ecbe65d15e05a8796619d Mon Sep 17 00:00:00 2001 From: bretello Date: Mon, 17 Jul 2017 02:03:37 +0200 Subject: [PATCH 05/10] Fixed typo --- brethil_dotfile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brethil_dotfile.sh b/brethil_dotfile.sh index 6b1e590..facca6f 100755 --- a/brethil_dotfile.sh +++ b/brethil_dotfile.sh @@ -8,7 +8,7 @@ uname=$(uname -a) if [[ $uname == *"Darwin"* ]]; then if [[ $(which brew) ]]; then os_extra=(osx brew) - elif [[ $(which port)]]; then + elif [[ $(which port) ]]; then os_extra=(osx macports) else os_extra=(osx) From 50f8012ed9e911c9a73fc860416123f138786c24 Mon Sep 17 00:00:00 2001 From: bretello Date: Mon, 17 Jul 2017 02:43:42 +0200 Subject: [PATCH 06/10] Removed brew from default plugins --- brethil_dotfile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brethil_dotfile.sh b/brethil_dotfile.sh index facca6f..a7b1c98 100755 --- a/brethil_dotfile.sh +++ b/brethil_dotfile.sh @@ -2,7 +2,7 @@ env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $DOTFILES/check_for_update.sh # oh-my-zsh plugins (some of these have to be installed by running install.sh or install_zsh_plugins, found in install.sh) -shared_plugins=(git brew common-aliases fast-syntax-highlighting zsh-autosuggestions colored-man-pages zsh-navigation-tools zsh_reload sudo alias-tips) +shared_plugins=(git alias-tips sudo common-aliases fast-syntax-highlighting zsh-autosuggestions colored-man-pages zsh-navigation-tools zsh_reload ) uname=$(uname -a) if [[ $uname == *"Darwin"* ]]; then From 7c9dc917dddb2f3a2a4bc58acfe6dbe1b5cbcfff Mon Sep 17 00:00:00 2001 From: bretello Date: Tue, 18 Jul 2017 15:57:26 +0200 Subject: [PATCH 07/10] Updated grc aliases --- aliases.sh | 60 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/aliases.sh b/aliases.sh index 991f90e..b3621f7 100755 --- a/aliases.sh +++ b/aliases.sh @@ -72,27 +72,45 @@ alias ssh1="ssh -o ControlMaster=no" # Some colorizing options for grc -GRC=$(which grc) -if [ "$TERM" != dumb ] && [ -n "$GRC" ]; then - #alias colourify="$GRC -es --colour=auto" - alias colourify="$GRC --colour=auto" - alias configure='colourify ./configure' - alias diff='colourify diff' - alias make='colourify make' - alias gcc='colourify gcc' - alias g++='colourify g++' - alias as='colourify as' - alias gas='colourify gas' - alias ld='colourify ld' - alias netstat='colourify netstat' - alias ping='colourify ping' - alias traceroute='colourify /usr/sbin/traceroute' - alias head='colourify head' - alias tail='colourify tail' - alias dig='colourify dig' - alias mount='colourify mount' - alias ps='colourify ps' - alias mtr='colourify mtr' +if [[ "$TERM" != dumb ]] && (( $+commands[grc] )) ; then + # Prevent grc aliases from overriding zsh completions. + setopt COMPLETE_ALIASES + + # Supported commands + cmds=( + cc \ + configure \ + cvs \ + df \ + diff \ + dig \ + gcc \ + gmake \ + ifconfig \ + last \ + ldap \ + ls \ + make \ + mount \ + mtr \ + netstat \ + ping \ + ping6 \ + ps \ + traceroute \ + traceroute6 \ + wdiff \ + ); + + # Set alias for available commands. + for cmd in $cmds ; do + if (( $+commands[$cmd] )) ; then + alias $cmd="grc --colour=auto $cmd" + fi + done + + # Clean up variables + unset cmds cmd fi if [[ -f ~/.dotfiles_aliases ]]; From cf0b5ee0f18f34d94e74fca878efe9d9dbe35e6a Mon Sep 17 00:00:00 2001 From: bretello Date: Tue, 8 Aug 2017 10:38:27 +0200 Subject: [PATCH 08/10] Bugfixes --- aliases.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aliases.sh b/aliases.sh index b3621f7..30b9c52 100755 --- a/aliases.sh +++ b/aliases.sh @@ -72,7 +72,7 @@ alias ssh1="ssh -o ControlMaster=no" # Some colorizing options for grc -if [[ "$TERM" != dumb ]] && (( $+commands[grc] )) ; then +if [[ "$TERM" != dumb ]] && [[ -f $(which grc) ]] ; then # Prevent grc aliases from overriding zsh completions. setopt COMPLETE_ALIASES @@ -89,7 +89,6 @@ if [[ "$TERM" != dumb ]] && (( $+commands[grc] )) ; then ifconfig \ last \ ldap \ - ls \ make \ mount \ mtr \ @@ -104,7 +103,7 @@ if [[ "$TERM" != dumb ]] && (( $+commands[grc] )) ; then # Set alias for available commands. for cmd in $cmds ; do - if (( $+commands[$cmd] )) ; then + if [[ -f $(which $cmd) ]] ; then alias $cmd="grc --colour=auto $cmd" fi done From 2c0f91f5c20796ae588edf1e490306d2877c3911 Mon Sep 17 00:00:00 2001 From: bretello Date: Tue, 8 Aug 2017 10:52:00 +0200 Subject: [PATCH 09/10] Fixed autoupdater script --- brethil_dotfile.sh | 2 +- check_for_update.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/brethil_dotfile.sh b/brethil_dotfile.sh index a7b1c98..cae0e0e 100755 --- a/brethil_dotfile.sh +++ b/brethil_dotfile.sh @@ -1,5 +1,5 @@ # Check for update, set DISABLE_UPDATE_PROMPT=yes to disable the prompt and automatically update -env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $DOTFILES/check_for_update.sh +env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT DOTFILES=$DOTFILES zsh -f $DOTFILES/check_for_update.sh # oh-my-zsh plugins (some of these have to be installed by running install.sh or install_zsh_plugins, found in install.sh) shared_plugins=(git alias-tips sudo common-aliases fast-syntax-highlighting zsh-autosuggestions colored-man-pages zsh-navigation-tools zsh_reload ) diff --git a/check_for_update.sh b/check_for_update.sh index 3894c23..c5808ea 100755 --- a/check_for_update.sh +++ b/check_for_update.sh @@ -26,13 +26,13 @@ if [[ -z "$epoch_target" ]]; then fi # Cancel upgrade if the current user doesn't have write permissions for the -# oh-my-zsh directory. -[[ -w "$ZSH" ]] || return 0 +# dotfiles directory. +[[ -w "$DOTFILES" ]] || return 0 # Cancel upgrade if git is unavailable on the system whence git >/dev/null || return 0 -if mkdir "$DOTFILES/log/update.lock" 2>/dev/null; then +if mkdir "$DOTFILES/update.lock" 2>/dev/null; then if [ -f ~/.dotfiles-update ]; then . ~/.dotfiles-update @@ -59,5 +59,5 @@ if mkdir "$DOTFILES/log/update.lock" 2>/dev/null; then _update_dotfiles_update fi - rmdir $DOTFILES/log/update.lock + rmdir $DOTFILES/update.lock fi From 5b807df53ea38cf9608f92a3fe58430f2d0cee58 Mon Sep 17 00:00:00 2001 From: bretello Date: Fri, 10 Nov 2017 01:24:10 +0100 Subject: [PATCH 10/10] Added ls as grc-supported command --- aliases.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/aliases.sh b/aliases.sh index 30b9c52..16acea2 100755 --- a/aliases.sh +++ b/aliases.sh @@ -10,21 +10,21 @@ if [[ "$(uname)" == "Darwin" ]]; then alias ls="ls -G" ## Colorize system.log contents (with grc), and inspect with less. alias console="grc cat /var/log/system.log | sort -r | less -R" - + ## Quicklook shortcut alias quicklook='qlmanage -px 2>/dev/null' - alias ql='qlmanage -px' - + alias ql='quicklook' + ## Airport command line interface alias airport='/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport' - + ## Set an English locale to awk (default is italian, with commas as decimal separators) alias awk='LC_ALL=en_DK awk' - + ## Flush dns cache #alias dnsflushcache='sudo discoveryutil mdnsflushcache' # used to work until 10.6 alias dnsflushcache='sudo killall -HUP mDNSResponder' # Works up until 10.9 and after 10.10.4 - + ## Add opened files to Textmate's recent menu item alias mate='mate --recent' fi @@ -56,7 +56,7 @@ alias upcd='. upcd.sh' ## Show the last 10 modified files alias lsrt="ls -lrt | tail -10" -## List open connections, TCP and UDP +## List open connections, TCP and UDP alias listconnections="lsof -n -i TCP -i UDP" ## Stress (run stress &>/dev/null &) alias stress='yes >> /dev/null' @@ -68,7 +68,7 @@ alias mdiff="mate -t source.diff" #### SSH Tunnels # ########################### # define ssh without controlmaster -alias ssh1="ssh -o ControlMaster=no" +alias ssh1="ssh -o ControlMaster=no" # Some colorizing options for grc @@ -78,6 +78,7 @@ if [[ "$TERM" != dumb ]] && [[ -f $(which grc) ]] ; then # Supported commands cmds=( + ls \ cc \ configure \ cvs \