1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-11-24 12:31:31 +01:00

1. New system to handle oh-my-zsh plugins (stored in the $plugins variable in brethil_dotfile.sh)

2. Added minimal zsh theme (brethil-minimal)
3. Misc improvements to install script
4. Autoupdate script (git pull)
5. New zsh plugins: syntax highlighting, history navigation, alias tips, sudo (type esc twice to add sudo before command)
6. Minor fixes
This commit is contained in:
bretello 2017-11-10 16:06:32 +01:00
commit dcd53f33aa
8 changed files with 431 additions and 259 deletions

View File

@ -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,37 +15,44 @@ 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 ###
### Installed ###
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)
Two zsh themes: brethil and brethil-minimal.
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
### 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
@ -53,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, installed in ~/.oh-my-zsh/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 `ls`/`grep`/`man`
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 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)
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.

View File

@ -2,7 +2,6 @@
#### ALIAS #
###########################
####
#### Easier life (MAC SPECIFIC)
####
@ -14,7 +13,7 @@ if [[ "$(uname)" == "Darwin" ]]; then
## 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'
@ -36,11 +35,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}'"
@ -58,12 +56,8 @@ alias upcd='. upcd.sh'
## Show the last 10 modified files
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 +70,48 @@ 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
if [[ "$TERM" != dumb ]] && [[ -f $(which grc) ]] ; then
# Prevent grc aliases from overriding zsh completions.
setopt COMPLETE_ALIASES
# Supported commands
cmds=(
ls \
cc \
configure \
cvs \
df \
diff \
dig \
gcc \
gmake \
ifconfig \
last \
ldap \
make \
mount \
mtr \
netstat \
ping \
ping6 \
ps \
traceroute \
traceroute6 \
wdiff \
);
# Set alias for available commands.
for cmd in $cmds ; do
if [[ -f $(which $cmd) ]] ; then
alias $cmd="grc --colour=auto $cmd"
fi
done
# Clean up variables
unset cmds cmd
fi
if [[ -f ~/.dotfiles_aliases ]];
then

View File

@ -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%}"

View File

@ -1,57 +1,47 @@
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
# Check for update, set DISABLE_UPDATE_PROMPT=yes to disable the prompt and automatically update
env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT DOTFILES=$DOTFILES zsh -f $DOTFILES/check_for_update.sh
alias esource="mate -t source.shell $HOME/.zshrc"
# 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 )
uname=$(uname -a)
if [[ $uname == *"Darwin"* ]]; then
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
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"
# 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"
# Custom definitions files
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"
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/
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

63
check_for_update.sh Executable file
View File

@ -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
# dotfiles directory.
[[ -w "$DOTFILES" ]] || return 0
# Cancel upgrade if git is unavailable on the system
whence git >/dev/null || return 0
if mkdir "$DOTFILES/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/update.lock
fi

View File

@ -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"

View File

@ -1,31 +1,35 @@
###########################
#### Function Definitions #
###########################
## 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
function cheat
{
curl cheat.sh/$1
}
## Simple calculator. Usage: calc 1+1, calc 5/7, calc "sqrt(2)"
function calc {
function calc
{
awk "BEGIN { print "$*" }"
}
## Open Man in separate (good looking) window
function nman
{
if [ $# -eq 1 ] ;
then open x-man-page://$1 ;
elif [ $# -eq 2 ] ;
then open x-man-page://$1/$2 ;
fi
}
## 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 +51,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 </dev/tty;
}
## Same as above, only play music
## Same as above, only play music (uses mplayer)
function pmusic
{
echo 'https://www.youtube.com/results?search_query=HD%20'"$(sed 's/ /%20/g' <<< $(tr '\' '+' <<< "$@"))"; id=$(curl -s 'https://www.youtube.com/results?search_query='HD%20"$(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 </dev/tty;
@ -99,37 +105,36 @@ function httpserver
}
## Upload something using the transfer.sh service
## Upload something using the transfer.sh service. Usage: transfer filename
function transfer
{
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
out=$(curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile")
echo -e "Done, file at:\t$out"
if [[ $(uname) == "Darwin" ]]; then
echo "$out" | pbcopy
else
echo "$out"
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'
}
# If connecting through ssh and reverse forwarding port 2222 (ssh -R 2222:localhost:22 ), this function allows to copy the files back to the machine one is connecting from by typing 'mecp filename' (configure the username for "localhost" in ~/.ssh/config or add an username)
## If connecting through ssh and reverse forwarding port 2222 (ssh -R 2222:localhost:22 ), this function allows to copy the files back to the machine one is connecting from by typing 'mecp filename' (configure the username for "localhost" in ~/.ssh/config or add an username)
function mecp
{
rsync -r -P -e "ssh -p 2222" -R "$@" localhost:~/Desktop/
}
# generate a password using pwgen, generate_password 20 generates a 20 characters long password
## generate a password using pwgen, generate_password 20 generates a 20 characters long password
function generate_password
{
pwgen -1sycn $1
}
# Generate a password from dev urandom using only printable characters
function genpwd {
if [[ -e $1 ]]; then
## Generate a password from dev urandom using only printable characters
function genpwd
{
if [[ $1 ]]; then
strlen=$1
else
strlen=32
@ -139,26 +144,35 @@ function genpwd {
if [[ "$(uname)" == "Darwin" ]]; then
# Copy output of previous command to termbin.com (command line pastebin) and put in in clipboard
function termbin {
## Copy output of previous command to termbin.com (command line pastebin) and put in in clipboard
function termbin
{
nc termbin.com 9999 | pbcopy && echo -n "$(pbpaste) --> 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
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
function ramdisk
{
if [[ -e $1 ]]; then
sizeingb=$1
else
sizeingb=1
@ -179,13 +193,30 @@ then
echo " $ diskutil eject $mydev"
}
# Anybar support https://github.com/tonsky/AnyBar
function anybar { echo -n $1 | nc -4u -w0 localhost ${2:-1738}; }
## 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
if [[ -f ~/.dotfiles_functions ]]; then
source ~/.dotfiles_functions
fi

View File

@ -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
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
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 ]]; then
ssh-keygen -t rsa -b 4096 -C $comment
else
ssh-keygen -t rsa -b 4096
fi
# fix permissions
chmod 0700 "$HOME/.ssh"
fi
if [[ -f $ssh_config ]]; then
while [ "$modifyssh" != "y" ] && [ "$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
@ -66,114 +81,140 @@ function create_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 '## 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..."
# 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."
# Launch bash
$(which bash)
else
echo "Quitting."
exit 0
fi
elif [[ -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
sed -i 's/set -g terminal-overrides/#set -g terminal-overrides/' /usr/share/byobu/profiles/tmux
# oh-my-zsh's zshrc has been installed, prepend the dotfiles setup to it
cat $HOME/.zshrc >> $ZSHTMP
mv $ZSHTMP $HOME/.zshrc
echo "bind m setw -g mode-mouse on" >> ~/.tmux.conf
echo "bind M setw -g mode-mouse off" >> ~/.tmux.conf
# 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
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/
# 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
sed -i '' 's/ZSH_THEME=".*"/ZSH_THEME="brethil"/' $HOME/.zshrc
else
sed -i 's/ZSH_THEME=".*"/ZSH_THEME="brethil"/' $HOME/.zshrc
fi
}
@ -181,9 +222,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. )"