From 8aac4dca7f0174dd3df20d0b2bfb1f319fd47842 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Tue, 18 Oct 2016 21:06:04 +0100 Subject: [PATCH 1/5] Added back z.sh (bad Fergal) --- bashrc | 3 +++ z.sh | 83 +++++++++++++++++++++++++++++++--------------------------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/bashrc b/bashrc index 8c50ecb..49496db 100644 --- a/bashrc +++ b/bashrc @@ -101,6 +101,9 @@ if [ -f ~/.bash_functions ]; then source ~/.bash_functions fi +. ~/dotfiles/z.sh + + export ANDROID_SDK=/opt/android-sdk-linux/ export PATH=$PATH:/opt/android-sdk-linux/tools:/opt/android-sdk-linux/platform-tools/:/opt/genymotion export SENCHA_CMD_3_0_0="/home/fergalm/dev/sencha/Sencha/Cmd/4.0.0.203" diff --git a/z.sh b/z.sh index 786bdfd..24e1272 100755 --- a/z.sh +++ b/z.sh @@ -13,6 +13,7 @@ # set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution. # set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself. # set $_Z_EXCLUDE_DIRS to an array of directories to exclude. +# set $_Z_OWNER to your username if you want use z while sudo with $HOME kept # # USE: # * z foo # cd to most frecent dir matching foo @@ -30,8 +31,16 @@ _z() { local datafile="${_Z_DATA:-$HOME/.z}" - # bail if we don't own ~/.z (we're another user but our ENV is still set) - [ -f "$datafile" -a ! -O "$datafile" ] && return + # bail if we don't own ~/.z and $_Z_OWNER not set + [ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return + + _z_dirs () { + while read line; do + # only count directories + [ -d "${line%%\|*}" ] && echo $line + done < "$datafile" + return 0 + } # add entries if [ "$1" = "--add" ]; then @@ -40,18 +49,15 @@ _z() { # $HOME isn't worth matching [ "$*" = "$HOME" ] && return - # don't track excluded dirs + # don't track excluded directory trees local exclude for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do - [ "$*" = "$exclude" ] && return + case "$*" in "$exclude*") return;; esac done # maintain the data file local tempfile="$datafile.$RANDOM" - while read line; do - # only count directories - [ -d "${line%%\|*}" ] && echo $line - done < "$datafile" | awk -v path="$*" -v now="$(date +%s)" -F"|" ' + awk < <(_z_dirs 2>/dev/null) -v path="$*" -v now="$(date +%s)" -F"|" ' BEGIN { rank[path] = 1 time[path] = now @@ -68,35 +74,34 @@ _z() { count += $2 } END { - if( count > 6000 ) { + if( count > 9000 ) { # aging for( x in rank ) print x "|" 0.99*rank[x] "|" time[x] } else for( x in rank ) print x "|" rank[x] "|" time[x] } ' 2>/dev/null >| "$tempfile" - # do our best to avoid clobbering the datafile in a race condition + # do our best to avoid clobbering the datafile in a race condition. if [ $? -ne 0 -a -f "$datafile" ]; then env rm -f "$tempfile" else + [ "$_Z_OWNER" ] && chown $_Z_OWNER:$(id -ng $_Z_OWNER) "$tempfile" env mv -f "$tempfile" "$datafile" || env rm -f "$tempfile" fi # tab completion - elif [ "$1" = "--complete" ]; then + elif [ "$1" = "--complete" -a -s "$datafile" ]; then while read line; do [ -d "${line%%\|*}" ] && echo $line done < "$datafile" | awk -v q="$2" -F"|" ' BEGIN { if( q == tolower(q) ) imatch = 1 - split(substr(q, 3), fnd, " ") + q = substr(q, 3) + gsub(" ", ".*", q) } { if( imatch ) { - for( x in fnd ) tolower($1) !~ tolower(fnd[x]) && $1 = "" - } else { - for( x in fnd ) $1 !~ fnd[x] && $1 = "" - } - if( $1 ) print $1 + if( tolower($1) ~ tolower(q) ) print $1 + } else if( $1 ~ q ) print $1 } ' 2>/dev/null @@ -106,29 +111,28 @@ _z() { --) while [ "$1" ]; do shift; local fnd="$fnd${fnd:+ }$1";done;; -*) local opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in c) local fnd="^$PWD $fnd";; - h) echo "${_Z_CMD:-z} [-chlrtx] args" >&2; return;; - x) sed -i "\:^${PWD}|.*:d" "$datafile";; + e) local echo=echo;; + h) echo "${_Z_CMD:-z} [-cehlrtx] args" >&2; return;; l) local list=1;; r) local typ="rank";; t) local typ="recent";; + x) sed -i -e "\:^${PWD}|.*:d" "$datafile";; esac; opt=${opt:1}; done;; *) local fnd="$fnd${fnd:+ }$1";; - esac; local last=$1; shift; done + esac; local last=$1; [ "$#" -gt 0 ] && shift; done [ "$fnd" -a "$fnd" != "^$PWD " ] || local list=1 # if we hit enter on a completion just go there case "$last" in # completions will always start with / - /*) [ -z "$list" -a -d "$last" ] && cd "$last" && return;; + /*) [ -z "$list" -a -d "$last" ] && builtin cd "$last" && return;; esac # no file yet [ -f "$datafile" ] || return local cd - cd="$(while read line; do - [ -d "${line%%\|*}" ] && echo $line - done < "$datafile" | awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" ' + cd="$( < <( _z_dirs ) awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" ' function frecent(rank, time) { # relate frequency and time dx = t - time @@ -163,22 +167,23 @@ _z() { # use a copy to escape special characters, as we want to return # the original. yeah, this escaping is awful. clean_short = short - gsub(/[\(\)\[\]\|]/, "\\\\&", clean_short) + gsub(/\[\(\)\[\]\|\]/, "\\\\&", clean_short) for( x in matches ) if( matches[x] && x !~ clean_short ) return return short } - BEGIN { split(q, words, " "); hi_rank = ihi_rank = -9999999999 } + BEGIN { + gsub(" ", ".*", q) + hi_rank = ihi_rank = -9999999999 + } { if( typ == "rank" ) { rank = $2 } else if( typ == "recent" ) { rank = $3 - t } else rank = frecent($2, $3) - matches[$1] = imatches[$1] = rank - for( x in words ) { - if( $1 !~ words[x] ) delete matches[$1] - if( tolower($1) !~ tolower(words[x]) ) delete imatches[$1] - } + if( $1 ~ q ) { + matches[$1] = rank + } else if( tolower($1) ~ tolower(q) ) imatches[$1] = rank if( matches[$1] && matches[$1] > hi_rank ) { best_match = $1 hi_rank = matches[$1] @@ -196,8 +201,10 @@ _z() { } } ')" - [ $? -gt 0 ] && return - [ "$cd" ] && cd "$cd" + + [ $? -eq 0 ] && [ "$cd" ] && { + if [ "$echo" ]; then echo "$cd"; else builtin cd "$cd"; fi + } fi } @@ -205,17 +212,17 @@ alias ${_Z_CMD:-z}='_z 2>&1' [ "$_Z_NO_RESOLVE_SYMLINKS" ] || _Z_RESOLVE_SYMLINKS="-P" -if compctl >/dev/null 2>&1; then +if type compctl >/dev/null 2>&1; then # zsh [ "$_Z_NO_PROMPT_COMMAND" ] || { # populate directory list, avoid clobbering any other precmds. if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then _z_precmd() { - _z --add "${PWD:a}" + (_z --add "${PWD:a}" &) } else _z_precmd() { - _z --add "${PWD:A}" + (_z --add "${PWD:A}" &) } fi [[ -n "${precmd_functions[(r)_z_precmd]}" ]] || { @@ -229,14 +236,14 @@ if compctl >/dev/null 2>&1; then reply=(${(f)"$(_z --complete "$compl")"}) } compctl -U -K _z_zsh_tab_completion _z -elif complete >/dev/null 2>&1; then +elif type complete >/dev/null 2>&1; then # bash # tab completion complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z} [ "$_Z_NO_PROMPT_COMMAND" ] || { # populate directory list. avoid clobbering other PROMPT_COMMANDs. grep "_z --add" <<< "$PROMPT_COMMAND" >/dev/null || { - PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''_z --add "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;' + PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''(_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null &);' } } fi From 01ebabb643e48f6626dedf2e56d7f9fb28a4d0fe Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Thu, 3 Nov 2016 21:39:47 +0000 Subject: [PATCH 2/5] Changed some aliases --- bash_aliases | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash_aliases b/bash_aliases index 6d14654..18f7211 100644 --- a/bash_aliases +++ b/bash_aliases @@ -12,12 +12,12 @@ alias dss_radio="cd ~/dev/personal/deepsouthsounds.com/dss.radio && workon dss.r alias pgdo="sudo -u postgres" alias sqlw="sqlw &" alias se="/opt/StorageExplorer/StorageExplorer > /dev/null 2>&1 &" -alias dbv="/usr/local/bin/dbvis > /dev/null 2>&1 &" +alias dbv="dbeaver > /dev/null 2>&1 &" alias rsl="rslsync --config /home/fergalm/.config/resilio-sync/config.json" alias reloadbashrc="source ~/.bashrc" alias server="python -m SimpleHTTPServer 9999" -alias upd="sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove" +alias upd="sudo apt update && sudo apt dist-upgrade && sudo apt autoremove" alias psql="sudo -u postgres psql deepsouthsounds" alias code="/usr/bin/code-insiders" From 98e66ecca72c0c06cb7bf41e8e1758f3bd284910 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Tue, 29 Nov 2016 23:31:14 +0000 Subject: [PATCH 3/5] Added zshrc --- bash_aliases | 2 +- bash_functions | 7 ----- bashrc | 12 +++++++ install.sh | 2 +- zshrc | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 zshrc diff --git a/bash_aliases b/bash_aliases index 18f7211..7b1f6c9 100644 --- a/bash_aliases +++ b/bash_aliases @@ -50,7 +50,7 @@ doPsKill(){ } alias pskill=doPsKill -alias docker-nuke="docker rm -f $(docker ps -a -q) && docker rmi $(docker images -q)" +alias docker-nuke="docker rm $(docker ps -a -q) && docker rmi $(docker images -q)" alias dc='docker-compose' alias docker-rm-untagged='docker rmi -f $(docker images | grep "^" | awk "{print $3}")'} diff --git a/bash_functions b/bash_functions index 01208f4..dd8c7a4 100644 --- a/bash_functions +++ b/bash_functions @@ -35,10 +35,3 @@ cb() { function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;} -function installCode(){ - cd /tmp - sudo rm -rfv /opt/VSCode-linux-x64 - sudo unzip /tmp/VSCode-linux-x64-stable.zip -d /opt/ - sudo chown fergalm:fergalm /opt/VSCode-linux-x64 -R - sudo chown fergalm:fergalm /opt/VSCode-linux-x64 -} diff --git a/bashrc b/bashrc index 49496db..59c59d1 100644 --- a/bashrc +++ b/bashrc @@ -95,6 +95,9 @@ if ! shopt -oq posix; then . /etc/bash_completion fi fi +#use known hosts for bash autocomplete - this needs "HashKnown Hosts no" in ~/.ssh/config +complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh + # Include functions file if [ -f ~/.bash_functions ]; then @@ -120,3 +123,12 @@ shopt -s histappend # append to history, don't overwrite it # Save and reload the history after each command finishes export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" + +VIRTUALENVWRAPPER=/usr/local/bin/virtualenvwrapper.sh +if [ -f $VIRTUALENVWRAPPER ]; +then + export WORKON_HOME=$HOME/.virtualenvs + export PROJECT_HOME=$HOME/dev/personal + source /usr/local/bin/virtualenvwrapper.sh +fi + diff --git a/install.sh b/install.sh index 15eff14..d84543a 100755 --- a/install.sh +++ b/install.sh @@ -6,7 +6,7 @@ h dir=~/dotfiles # dotfiles directory olddir=~/dotfiles_old # old dotfiles backup directory -files="bashrc bash_aliases bash_profile bash_prompt bash_functions sqliterc" # list of files/folders to symlink in homedir +files="zshrc bashrc bash_aliases bash_profile bash_prompt bash_functions sqliterc" # list of files/folders to symlink in homedir ########## diff --git a/zshrc b/zshrc new file mode 100644 index 0000000..1ba5861 --- /dev/null +++ b/zshrc @@ -0,0 +1,85 @@ +# If you come from bash you might have to change your $PATH. +# export PATH=$HOME/bin:/usr/local/bin:$PATH + +# Path to your oh-my-zsh installation. + export ZSH=/home/fergalm/.oh-my-zsh + +# Set name of the theme to load. Optionally, if you set this to "random" +# it'll load a random theme each time that oh-my-zsh is loaded. +# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes +ZSH_THEME="agnoster" + +# Uncomment the following line to use case-sensitive completion. +# CASE_SENSITIVE="true" + +# Uncomment the following line to use hyphen-insensitive completion. Case +# sensitive completion must be off. _ and - will be interchangeable. +# HYPHEN_INSENSITIVE="true" + +# Uncomment the following line to disable bi-weekly auto-update checks. +# DISABLE_AUTO_UPDATE="true" + +# Uncomment the following line to change how often to auto-update (in days). +# export UPDATE_ZSH_DAYS=13 + +# Uncomment the following line to disable colors in ls. +# DISABLE_LS_COLORS="true" + +# Uncomment the following line to disable auto-setting terminal title. +# DISABLE_AUTO_TITLE="true" + +# Uncomment the following line to enable command auto-correction. +# ENABLE_CORRECTION="true" + +# Uncomment the following line to display red dots whilst waiting for completion. +# COMPLETION_WAITING_DOTS="true" + +# Uncomment the following line if you want to disable marking untracked files +# under VCS as dirty. This makes repository status check for large repositories +# much, much faster. +# DISABLE_UNTRACKED_FILES_DIRTY="true" + +# Uncomment the following line if you want to change the command execution time +# stamp shown in the history command output. +# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" +# HIST_STAMPS="mm/dd/yyyy" + +# Would you like to use another custom folder than $ZSH/custom? +# ZSH_CUSTOM=/path/to/new-custom-folder + +# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) +# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ +# Example format: plugins=(rails git textmate ruby lighthouse) +# Add wisely, as too many plugins slow down shell startup. +plugins=(git) + +source $ZSH/oh-my-zsh.sh + +# User configuration + +# export MANPATH="/usr/local/man:$MANPATH" + +# You may need to manually set your language environment +# export LANG=en_US.UTF-8 + +# Preferred editor for local and remote sessions +# if [[ -n $SSH_CONNECTION ]]; then +# export EDITOR='vim' +# else +# export EDITOR='mvim' +# fi + +# Compilation flags +# export ARCHFLAGS="-arch x86_64" + +# ssh +# export SSH_KEY_PATH="~/.ssh/rsa_id" + +# Set personal aliases, overriding those provided by oh-my-zsh libs, +# plugins, and themes. Aliases can be placed here, though oh-my-zsh +# users are encouraged to define aliases within the ZSH_CUSTOM folder. +# For a full list of active aliases, run `alias`. +# +# Example aliases +# alias zshconfig="mate ~/.zshrc" +# alias ohmyzsh="mate ~/.oh-my-zsh" From 0ff8962113c385bfb94eeaefd420b46aee0e0ca8 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Tue, 29 Nov 2016 23:48:17 +0000 Subject: [PATCH 4/5] zsh stuff --- .gitignore | 1 + bash_aliases | 2 +- install.sh | 10 +++++++--- zshrc | 5 +++-- 4 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e6aedd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pwfonts/ diff --git a/bash_aliases b/bash_aliases index 7b1f6c9..b10fde3 100644 --- a/bash_aliases +++ b/bash_aliases @@ -52,6 +52,6 @@ alias pskill=doPsKill alias docker-nuke="docker rm $(docker ps -a -q) && docker rmi $(docker images -q)" alias dc='docker-compose' -alias docker-rm-untagged='docker rmi -f $(docker images | grep "^" | awk "{print $3}")'} +alias docker-rm-untagged='docker rmi -f $(docker images | grep "^" | awk "{print $3}")' diff --git a/install.sh b/install.sh index d84543a..849c36c 100755 --- a/install.sh +++ b/install.sh @@ -6,7 +6,7 @@ h dir=~/dotfiles # dotfiles directory olddir=~/dotfiles_old # old dotfiles backup directory -files="zshrc bashrc bash_aliases bash_profile bash_prompt bash_functions sqliterc" # list of files/folders to symlink in homedir +files="zshrc bash_aliases bash_functions sqliterc" # list of files/folders to symlink in homedir ########## @@ -32,5 +32,9 @@ done chmod +x $dir/dropbox.py ln -s $dir/dropbox.py ~/bin/dropbox.py -ln $dir/fonts ~/.fonts -fc-cache -f -v +#ln $dir/fonts ~/.fonts +#fc-cache -f -v + + +git clone https://github.com/powerline/fonts.git pwfonts +cd pwfonts && ./install.sh diff --git a/zshrc b/zshrc index 1ba5861..619ab13 100644 --- a/zshrc +++ b/zshrc @@ -2,12 +2,12 @@ # export PATH=$HOME/bin:/usr/local/bin:$PATH # Path to your oh-my-zsh installation. - export ZSH=/home/fergalm/.oh-my-zsh +export ZSH=/home/fergalm/.oh-my-zsh # Set name of the theme to load. Optionally, if you set this to "random" # it'll load a random theme each time that oh-my-zsh is loaded. # See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes -ZSH_THEME="agnoster" +ZSH_THEME="random" # Uncomment the following line to use case-sensitive completion. # CASE_SENSITIVE="true" @@ -54,6 +54,7 @@ ZSH_THEME="agnoster" plugins=(git) source $ZSH/oh-my-zsh.sh +source ~/.bash_aliases # User configuration From d6ec6482b24f63e98bb35de076c1927eae9bdf54 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Tue, 29 Nov 2016 23:49:21 +0000 Subject: [PATCH 5/5] Muse theme --- zshrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zshrc b/zshrc index 619ab13..da2661c 100644 --- a/zshrc +++ b/zshrc @@ -7,7 +7,7 @@ export ZSH=/home/fergalm/.oh-my-zsh # Set name of the theme to load. Optionally, if you set this to "random" # it'll load a random theme each time that oh-my-zsh is loaded. # See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes -ZSH_THEME="random" +ZSH_THEME="muse" # Uncomment the following line to use case-sensitive completion. # CASE_SENSITIVE="true"