diff --git a/.bash_aliases b/.bash_aliases index 562c507..6d3434c 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -10,30 +10,30 @@ #alias dir='ls --color=auto --format=vertical' #alias vdir='ls --color=auto --format=long' -case `uname` in -Linux) - if [ "$TERM" != "dumb" ]; then - eval "`dircolors -b`" - fi - alias ls='ls -F --color=auto' - alias open='xdg-open' - ;; -Darwin) - alias ls='ls -FG' - ;; -FreeBSD) - alias ls='ls -FG' - ;; -SunOS) - alias ls='ls -F' - ;; -*) - if [ "$TERM" != "dumb" ]; then - eval "`dircolors -b`" - fi - alias ls='ls --color=auto' - ;; -esac +#case `uname` in +#Linux) + #if [ "$TERM" != "dumb" ]; then + #eval "`dircolors -b`" + #fi + #alias ls='ls -F --color=auto' + #alias open='xdg-open' + #;; +#Darwin) + #alias ls='ls -FG' + #;; +#FreeBSD) + #alias ls='ls -FG' + #;; +#SunOS) + #alias ls='ls -F' + #;; +#*) + #if [ "$TERM" != "dumb" ]; then + #eval "`dircolors -b`" + #fi + #alias ls='ls --color=auto' + #;; +#esac @@ -45,6 +45,7 @@ alias la='ls -alF' #alias l='ls -CF' alias :e='vim' +alias t='task' alias vi='vim' alias em='emacs' alias grep="grep --color=auto" @@ -52,7 +53,7 @@ alias grep="grep --color=auto" alias dvtm="dvtm -m \"^w\"" alias tm="tmux -2 attach" alias ppjson="python -mjson.tool" -alias tmux-pwn='tmux list-clients | sed "s|^\(/dev/ttys[0-9]\+\).*\[\([0-9]\+x[0-9]\+\).*$|\2 \1|" | sort -r -n | tail -n +2 | cut -d " " -f 2 | xargs -n 1 tmux detach-client -t' +#alias tmux-pwn='tmux list-clients | sed "s|^\(/dev/ttys[0-9]\+\).*\[\([0-9]\+x[0-9]\+\).*$|\2 \1|" | sort -r -n | tail -n +2 | cut -d " " -f 2 | xargs -n 1 tmux detach-client -t' #Cosmetic/useful #alias naim="naim --noscreen" diff --git a/.bashrc b/.bashrc index 3bc9c26..e1cf881 100644 --- a/.bashrc +++ b/.bashrc @@ -99,6 +99,13 @@ if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi +fasd_cache="$HOME/.fasd-init-bash" +if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then + fasd --init posix-alias bash-hook bash-ccomp bash-ccomp-install >| "$fasd_cache" +fi +source "$fasd_cache" +unset fasd_cache + # enable color support of ls and also add handy aliases #if [ "$TERM" != "dumb" ]; then # eval "`dircolors -b`" diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index e61c652..53b5df2 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua @@ -156,7 +156,6 @@ function (widget, args) return args[2] end , 120, "BAT0") - -- Register CPU widget vicious.register(cpuwidget, vicious.widgets.cpu, function (widget, args) diff --git a/.config/fish/config.fish b/.config/fish/config.fish index 5bfc59a..b07e1e8 100644 --- a/.config/fish/config.fish +++ b/.config/fish/config.fish @@ -1,4 +1,5 @@ set PATH ~/bin /bin /sbin /usr/local/bin /usr/local/sbin /usr/bin /usr/sbin ~/.cabal/bin /usr/lib/go/bin ~/.gem/ruby/1.9.1/bin $PATH set fish_greeting "" + . ~/.bash_aliases diff --git a/.gitmodules b/.gitmodules index c49de8c..d951888 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,9 +10,6 @@ [submodule ".vim/bundle/NrrwRgn"] path = .vim/bundle/NrrwRgn url = git://github.com/chrisbra/NrrwRgn.git -[submodule ".vim/bundle/sparkup"] - path = .vim/bundle/sparkup - url = git://github.com/rstacruz/sparkup.git [submodule ".vim/bundle/ack.vim"] path = .vim/bundle/ack.vim url = git://github.com/mileszs/ack.vim.git @@ -64,3 +61,9 @@ [submodule ".vim/bundle/vim-angry"] path = .vim/bundle/vim-angry url = https://github.com/b4winckler/vim-angry.git +[submodule ".vim/bundle/YouCompleteMe"] + path = .vim/bundle/YouCompleteMe + url = https://github.com/Valloric/YouCompleteMe.git +[submodule ".vim/bundle/vim-sparkup"] + path = .vim/bundle/vim-sparkup + url = git://github.com/tristen/vim-sparkup.git diff --git a/.taskrc b/.taskrc new file mode 100644 index 0000000..64b58cf --- /dev/null +++ b/.taskrc @@ -0,0 +1,29 @@ +# [Created by task 2.2.0 5/9/2013 17:01:23] +# Taskwarrior program configuration file. +# For more documentation, see http://taskwarrior.org or try 'man task', 'man task-faq', +# 'man task-tutorial', 'man task-color', 'man task-sync' or 'man taskrc' + +# Here is an example of entries that use the default, override and blank values +# variable=foo -- By specifying a value, this overrides the default +# variable= -- By specifying no value, this means no default +# #variable=foo -- By commenting out the line, or deleting it, this uses the default + +# Use the command 'task show' to see all defaults and overrides + +# Files +data.location=~/.task +pull.default.uri=barak@miranda.barakmich.com:/fs/home/barak/.task +push.default.uri=barak@miranda.barakmich.com:/fs/home/barak/.task + +# Color theme (uncomment one to use) +#include /usr/share/doc/task/rc/light-16.theme +#include /usr/share/doc/task/rc/light-256.theme +#include /usr/share/doc/task/rc/dark-16.theme +#include /usr/share/doc/task/rc/dark-256.theme +#include /usr/share/doc/task/rc/dark-red-256.theme +#include /usr/share/doc/task/rc/dark-green-256.theme +#include /usr/share/doc/task/rc/dark-blue-256.theme +#include /usr/share/doc/task/rc/dark-violets-256.theme +#include /usr/share/doc/task/rc/dark-yellow-green.theme +#include /usr/share/doc/task/rc/dark-gray-256.theme + diff --git a/.vim/bundle/YouCompleteMe b/.vim/bundle/YouCompleteMe new file mode 160000 index 0000000..0c19ee4 --- /dev/null +++ b/.vim/bundle/YouCompleteMe @@ -0,0 +1 @@ +Subproject commit 0c19ee4fa78f69b4591fe107c104b07174cd661c diff --git a/.vim/bundle/fish-syntax b/.vim/bundle/fish-syntax index 34883e2..195fbd1 160000 --- a/.vim/bundle/fish-syntax +++ b/.vim/bundle/fish-syntax @@ -1 +1 @@ -Subproject commit 34883e28bbc021eae07d85f259150c4d5797457e +Subproject commit 195fbd1d31d0bab944b0b92fb7ffa83fb50c4524 diff --git a/.vim/bundle/nerdtree b/.vim/bundle/nerdtree index eaf1973..448ad6f 160000 --- a/.vim/bundle/nerdtree +++ b/.vim/bundle/nerdtree @@ -1 +1 @@ -Subproject commit eaf19734e73dbaa5b30f10591079043b0eba0aab +Subproject commit 448ad6f1bce0308329ccb020b51710227108b578 diff --git a/.vim/bundle/sparkup b/.vim/bundle/sparkup deleted file mode 160000 index 5041a10..0000000 --- a/.vim/bundle/sparkup +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5041a10515c98f69dd510b0486983eee1fa1697e diff --git a/.vim/bundle/syntastic b/.vim/bundle/syntastic index 6f214cb..7f0412e 160000 --- a/.vim/bundle/syntastic +++ b/.vim/bundle/syntastic @@ -1 +1 @@ -Subproject commit 6f214cbb6d42256031aaa9670cf9ea7358e18431 +Subproject commit 7f0412e91dd6e2b48cbe8ae54bddcfeca0c127c1 diff --git a/.vim/bundle/vim-fugitive b/.vim/bundle/vim-fugitive index 4c7e649..54ead5a 160000 --- a/.vim/bundle/vim-fugitive +++ b/.vim/bundle/vim-fugitive @@ -1 +1 @@ -Subproject commit 4c7e649efba289df0e7e8bb9abfa37f95b28f8ed +Subproject commit 54ead5abcbfdd776e1160b5510a129884c39f29c diff --git a/.vim/bundle/vim-gitgutter b/.vim/bundle/vim-gitgutter index 935184b..ff031d0 160000 --- a/.vim/bundle/vim-gitgutter +++ b/.vim/bundle/vim-gitgutter @@ -1 +1 @@ -Subproject commit 935184bd1806e37c1e3319c7f7f3ae94ef5a5313 +Subproject commit ff031d022f2123353bc93a3aa97290287c10a287 diff --git a/.vim/bundle/vim-multiple-cursors b/.vim/bundle/vim-multiple-cursors index 00219a9..679469e 160000 --- a/.vim/bundle/vim-multiple-cursors +++ b/.vim/bundle/vim-multiple-cursors @@ -1 +1 @@ -Subproject commit 00219a9f6f55394664abaeaad89de05fd5eaa7bc +Subproject commit 679469ed357e141b8b028e1a0c0a12752704fd7a diff --git a/.vim/bundle/vim-sparkup b/.vim/bundle/vim-sparkup new file mode 160000 index 0000000..b5e9269 --- /dev/null +++ b/.vim/bundle/vim-sparkup @@ -0,0 +1 @@ +Subproject commit b5e9269136ae8dc7d6fbd5ed8777cbcd8cc22fbf diff --git a/.vimrc b/.vimrc index d5827cf..70b4b89 100644 --- a/.vimrc +++ b/.vimrc @@ -162,7 +162,12 @@ let g:ConqueTerm_CWInsert = 1 let g:ConqueTerm_InsertOnEnter = 0 let g:ConqueTerm_SendVisKey = 'ss' -" * MiniBufExplorer +" * YouCompleteMe +let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py' +let g:ycm_confirm_extra_conf = 0 +"let g:ycm_add_preview_to_completeopt = 1 + +" * MinBufExplorer "let g:miniBufExplMapWindowNavVim = 1 "let g:miniBufExplMapWindowNavArrows = 1 "let g:miniBufExplMapCTabSwitchBufs = 1 @@ -180,7 +185,8 @@ let g:CommandTMaxDepth = 7 " let g:org_todo_setup='TODO | DONE' " while g:org_tag_setup is itself a string "let g:org_tag_setup='{@home(h) @work(w) @tennisclub(t)} \n {easy(e) hard(d)} \n {computer(c) phone(p)}' - +au! BufRead,BufWrite,BufWritePost,BufNewFile *.org +au BufEnter *.org call org#SetOrgFileType() " ** STATUSLINE ** diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py new file mode 100644 index 0000000..33ac6f6 --- /dev/null +++ b/.ycm_extra_conf.py @@ -0,0 +1,120 @@ +import os +import ycm_core +from clang_helpers import PrepareClangFlags + +# These are the compilation flags that will be used in case there's no +# compilation database set (by default, one is not set). +# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. +flags = [ +'-Wall', +'-Wextra', +'-Werror', +'-Wc++98-compat', +'-Wno-long-long', +'-Wno-variadic-macros', +'-fexceptions', +'-DNDEBUG', +'-DUSE_CLANG_COMPLETER', +# THIS IS IMPORTANT! Without a "-std=" flag, clang won't know which +# language to use when compiling headers. So it will guess. Badly. So C++ +# headers will be compiled as C headers. You don't want that so ALWAYS specify +# a "-std=". +# For a C project, you would set this to something like 'c99' instead of +# 'c++11'. +'-std=c++11', +# ...and the same thing goes for the magic -x option which specifies the +# language that the files to be compiled are written in. This is mostly +# relevant for c++ headers. +# For a C project, you would set this to 'c' instead of 'c++'. +'-x', +'c++', +'-isystem', +'../BoostParts', +'-isystem', +# This path will only work on OS X, but extra paths that don't exist are not +# harmful +'/System/Library/Frameworks/Python.framework/Headers', +'-isystem', +'../llvm/include', +'-isystem', +'../llvm/tools/clang/include', +'-I', +'.', +'-I', +'./ClangCompleter', +'-isystem', +'./tests/gmock/gtest', +'-isystem', +'./tests/gmock/gtest/include', +'-isystem', +'./tests/gmock', +'-isystem', +'./tests/gmock/include' +] + +# Set this to the absolute path to the folder (NOT the file!) containing the +# compile_commands.json file to use that instead of 'flags'. See here for +# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html +# +# Most projects will NOT need to set this to anything; you can just change the +# 'flags' list of compilation flags. Notice that YCM itself uses that approach. +compilation_database_folder = '' + +if compilation_database_folder: + database = ycm_core.CompilationDatabase( compilation_database_folder ) +else: + database = None + + +def DirectoryOfThisScript(): + return os.path.dirname( os.path.abspath( __file__ ) ) + + +def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): + if not working_directory: + return flags + new_flags = [] + make_next_absolute = False + path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] + for flag in flags: + new_flag = flag + + if make_next_absolute: + make_next_absolute = False + if not flag.startswith( '/' ): + new_flag = os.path.join( working_directory, flag ) + + for path_flag in path_flags: + if flag == path_flag: + make_next_absolute = True + break + + if flag.startswith( path_flag ): + path = flag[ len( path_flag ): ] + new_flag = path_flag + os.path.join( working_directory, path ) + break + + if new_flag: + new_flags.append( new_flag ) + return new_flags + + +def FlagsForFile( filename ): + if database: + # Bear in mind that compilation_info.compiler_flags_ does NOT return a + # python list, but a "list-like" StringVec object + compilation_info = database.GetCompilationInfoForFile( filename ) + final_flags = PrepareClangFlags( + MakeRelativePathsInFlagsAbsolute( + compilation_info.compiler_flags_, + compilation_info.compiler_working_dir_ ), + filename ) + + else: + relative_to = DirectoryOfThisScript() + final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) + + return { + 'flags': final_flags, + 'do_cache': True + } diff --git a/.zshenv b/.zshenv index fd518ba..7c207c9 100644 --- a/.zshenv +++ b/.zshenv @@ -10,8 +10,10 @@ bindkey '\e[6~' end-of-history # Page down key bindkey '\e[2~' redisplay # Insert key bindkey '\e[5~' insert-last-word # Page up key +export GOPATH="$HOME/.go/" + # remove /usr/games and /usr/X11R6/bin if you want -PATH=$HOME/bin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/games:/usr/X11R6/bin:/$HOME/.gem/ruby/1.9.1/bin:$HOME/.cabal/bin:/usr/lib/go/bin:$PATH; export PATH +PATH=$HOME/bin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/games:/usr/X11R6/bin:/$HOME/.gem/ruby/1.9.1/bin:$HOME/.cabal/bin:$HOME/.go/bin:/usr/lib/go/bin:$PATH; export PATH #PATH=$HOME/bin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/games:/usr/X11R6/bin:/$HOME/.gem/ruby/1.9/bin; export PATH case `uname` in SunOS) diff --git a/.zshrc b/.zshrc index f8fc2ee..a165395 100644 --- a/.zshrc +++ b/.zshrc @@ -82,6 +82,15 @@ source ~/.zprofile if [ -f ~/.bash_aliases ]; then source ~/.bash_aliases fi + +fasd_cache="$HOME/.fasd-init-zsh" +if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then + fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcompinstall >| "$fasd_cache" + fi +source "$fasd_cache" +unset fasd_cache + + source ~/.zshenv ############################################################## diff --git a/bin/fasd b/bin/fasd new file mode 100755 index 0000000..5ea0c73 --- /dev/null +++ b/bin/fasd @@ -0,0 +1,624 @@ +#!/usr/bin/env sh + +# Fasd (this file) can be sourced or executed by any POSIX compatible shell. + +# Fasd is originally written based on code from z (https://github.com/rupa/z) +# by rupa deadwyler under the WTFPL license. Most if not all of the code has +# been rewritten. + +# Copyright (C) 2011, 2012 by Wei Dai. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +fasd() { + + # make zsh do word splitting inside this function + [ "$ZSH_VERSION" ] && emulate sh && setopt localoptions + + case $1 in + --init) shift + while [ "$1" ]; do + case $1 in + env) + { # source rc files if present + [ -s "/etc/fasdrc" ] && . "/etc/fasdrc" + [ -s "$HOME/.fasdrc" ] && . "$HOME/.fasdrc" + + # set default options + [ -z "$_FASD_DATA" ] && _FASD_DATA="$HOME/.fasd" + [ -z "$_FASD_BLACKLIST" ] && _FASD_BLACKLIST="--help" + [ -z "$_FASD_SHIFT" ] && _FASD_SHIFT="sudo busybox" + [ -z "$_FASD_IGNORE" ] && _FASD_IGNORE="fasd ls echo" + [ -z "$_FASD_SINK" ] && _FASD_SINK=/dev/null + [ -z "$_FASD_TRACK_PWD" ] && _FASD_TRACK_PWD=1 + [ -z "$_FASD_MAX" ] && _FASD_MAX=2000 + [ -z "$_FASD_BACKENDS" ] && _FASD_BACKENDS=native + [ -z "$_FASD_FUZZY" ] && _FASD_FUZZY=2 + [ -z "$_FASD_VIMINFO" ] && _FASD_VIMINFO="$HOME/.viminfo" + [ -z "$_FASD_RECENTLY_USED_XBEL" ] && \ + _FASD_RECENTLY_USED_XBEL="$HOME/.local/share/recently-used.xbel" + + if [ -z "$_FASD_AWK" ]; then + # awk preferences + local awk; for awk in mawk gawk original-awk nawk awk; do + $awk "" && _FASD_AWK=$awk && break + done + fi + } >> "${_FASD_SINK:-/dev/null}" 2>&1 + ;; + + auto) cat <> "$_FASD_SINK" 2>&1 + +EOS + ;; + + posix-alias) cat <& /dev/null || fasd -d'; +EOS + ;; + + zsh-hook) cat <> "$_FASD_SINK" 2>&1 +} +autoload -Uz add-zsh-hook +add-zsh-hook preexec _fasd_preexec + +EOS + ;; + + bash-hook) cat <> "$_FASD_SINK" 2>&1 +} + +# add bash hook +case \$PROMPT_COMMAND in + *_fasd_prompt_func*) ;; + *) PROMPT_COMMAND="_fasd_prompt_func;\$PROMPT_COMMAND";; +esac + +EOS + ;; + + posix-hook) cat <> "$_FASD_SINK" 2>&1 +} +case \$PS1 in + *_fasd_ps1_func*) ;; + *) export PS1="\\\$(_fasd_ps1_func)\$PS1";; +esac + +EOS + ;; + + tcsh-hook) cat <& /dev/null'; +EOS + + ;; + + zsh-ccomp) cat <> "$_FASD_SINK" | \\ + sort -nr | sed 's/^[^ ]*[ ]*//' | while read -r line; do + compadd -U -V fasd "\$line" + done + compstate[insert]=menu # no expand + } + _fasd_zsh_word_complete_f() { _fasd_zsh_word_complete f ; } + _fasd_zsh_word_complete_d() { _fasd_zsh_word_complete d ; } + _fasd_zsh_word_complete_trigger() { + local _fasd_cur="\${words[CURRENT]}" + eval \$(fasd --word-complete-trigger _fasd_zsh_word_complete \$_fasd_cur) + } + # define zle widgets + zle -C fasd-complete complete-word _generic + zstyle ':completion:fasd-complete:*' completer _fasd_zsh_word_complete + zstyle ':completion:fasd-complete:*' menu-select + + zle -C fasd-complete-f complete-word _generic + zstyle ':completion:fasd-complete-f:*' completer _fasd_zsh_word_complete_f + zstyle ':completion:fasd-complete-f:*' menu-select + + zle -C fasd-complete-d complete-word _generic + zstyle ':completion:fasd-complete-d:*' completer _fasd_zsh_word_complete_d + zstyle ':completion:fasd-complete-d:*' menu-select +} + +EOS + ;; + + zsh-ccomp-install) cat <> "$_FASD_SINK" | sed -n "\\\$s/^.*'\\\\(.*\\\\)'/\\\\1/p") + \${COMP_LINE#* }" | while read -r line; do + quote_readline "\$line" 2>/dev/null || \\ + printf %q "\$line" 2>/dev/null && \\ + printf \\\\n + done) + local IFS=\$'\\n'; COMPREPLY=( \$RESULT ) +} +_fasd_bash_hook_cmd_complete() { + for cmd in \$*; do + complete -F _fasd_bash_cmd_complete \$cmd + done +} + +EOS + ;; + + bash-ccomp-install) cat <$`{}]\{1,\}/\1 /g' + ;; + + --proc) shift # process commands + # stop if we don't own $_FASD_DATA or $_FASD_RO is set + [ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return + + # blacklists + local each; for each in $_FASD_BLACKLIST; do + case " $* " in *\ $each\ *) return;; esac + done + + # shifts + while true; do + case " $_FASD_SHIFT " in + *\ $1\ *) shift;; + *) break;; + esac + done + + # ignores + case " $_FASD_IGNORE " in + *\ $1\ *) return;; + esac + + shift; fasd --add "$@" # add all arguments except command + ;; + + --add|-A) shift # add entries + # stop if we don't own $_FASD_DATA or $_FASD_RO is set + [ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return + + # find all valid path arguments, convert them to simplest absolute form + local paths="$(while [ "$1" ]; do + [ -e "$1" ] && printf %s\\n "$1"; shift + done | sed '/^[^/]/s@^@'"$PWD"'/@ + s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0 + s@[^/][^/]*//*\.\./@/@;t 0 + s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@;s@^$@/@' 2>> "$_FASD_SINK" \ + | tr '\n' '|')" + + # add current pwd if the option is set + [ "$_FASD_TRACK_PWD" = "1" -a "$PWD" != "$HOME" ] && paths="$paths|$PWD" + + [ -z "${paths##\|}" ] && return # stop if we have nothing to add + + # maintain the file + local tempfile + tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return + $_FASD_AWK -v list="$paths" -v now="$(date +%s)" -v max="$_FASD_MAX" -F"|" ' + BEGIN { + split(list, files, "|") + for(i in files) { + path = files[i] + if(path == "") continue + paths[path] = path # array for checking + rank[path] = 1 + time[path] = now + } + } + $2 >= 1 { + if($1 in paths) { + rank[$1] = $2 + 1 / $2 + time[$1] = now + } else { + rank[$1] = $2 + time[$1] = $3 + } + count += $2 + } + END { + if(count > max) + for(i in rank) print i "|" 0.9*rank[i] "|" time[i] # aging + else + for(i in rank) print i "|" rank[i] "|" time[i] + }' "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile" + if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then + env rm -f "$tempfile" + else + env mv -f "$tempfile" "$_FASD_DATA" + fi + ;; + + --delete|-D) shift # delete entries + # stop if we don't own $_FASD_DATA or $_FASD_RO is set + [ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return + + # turn valid arguments into entry-deleting sed commands + local sed_cmd="$(while [ "$1" ]; do printf %s\\n "$1"; shift; done | \ + sed '/^[^/]/s@^@'"$PWD"'/@;s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0 + s@[^/][^/]*//*\.\./@/@;t 0 + s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@ + s@^$@/@;s@\([.[\/*^$]\)@\\\1@g;s@^\(.*\)$@/^\1|/d@' 2>> "$_FASD_SINK")" + + # maintain the file + local tempfile + tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return + + sed "$sed_cmd" "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile" + + if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then + env rm -f "$tempfile" + else + env mv -f "$tempfile" "$_FASD_DATA" + fi + ;; + + --query) shift # query the db, --query [$typ ["$fnd" [$mode]]] + [ -f "$_FASD_DATA" ] || return # no db yet + [ "$1" ] && local typ="$1" + [ "$2" ] && local fnd="$2" + [ "$3" ] && local mode="$3" + + # cat all backends + local each _fasd_data; for each in $_FASD_BACKENDS; do + _fasd_data="$_fasd_data +$(fasd --backend $each)" + done + [ "$_fasd_data" ] || _fasd_data="$(cat "$_FASD_DATA")" + + # set mode specific code for calculating the prior + case $mode in + rank) local prior='times[i]';; + recent) local prior='sqrt(100000/(1+t-la[i]))';; + *) local prior='times[i] * frecent(la[i])';; + esac + + if [ "$fnd" ]; then # dafault matching + local bre="$(printf %s\\n "$fnd" | sed 's/\([*\.\\\[]\)/\\\1/g + s@ @[^|]*@g;s/\$$/|/')" + bre='^[^|]*'"$bre"'[^|/]*|' + local _ret="$(printf %s\\n "$_fasd_data" | grep "$bre")" + [ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do + [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" + done)" + if [ "$_ret" ]; then + _fasd_data="$_ret" + else # no case mathcing + _ret="$(printf %s\\n "$_fasd_data" | grep -i "$bre")" + [ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do + [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" + done)" + if [ "$_ret" ]; then + _fasd_data="$_ret" + elif [ "${_FASD_FUZZY:-0}" -gt 0 ]; then # fuzzy matching + local fuzzy_bre="$(printf %s\\n "$fnd" | \ + sed 's/\([*\.\\\[]\)/\\\1/g;s/\$$/|/ + s@\(\\\{0,1\}[^ ]\)@\1[^|/]\\{0,'"$_FASD_FUZZY"'\\}@g + s@ @[^|]*@g')" + fuzzy_bre='^[^|]*'"$fuzzy_bre"'[^|/]*|' + _ret="$(printf %s\\n "$_fasd_data" | grep -i "$fuzzy_bre")" + [ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do + [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" + done)" + [ "$_ret" ] && _fasd_data="$_ret" || _fasd_data= + fi + fi + else # no query arugments + _fasd_data="$(printf %s\\n "$_fasd_data" | while read -r line; do + [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" + done)" + fi + + # query the database + [ "$_fasd_data" ] && printf %s\\n "$_fasd_data" | \ + $_FASD_AWK -v t="$(date +%s)" -F"|" ' + function frecent(time) { + dx = t-time + if( dx < 3600 ) return 6 + if( dx < 86400 ) return 4 + if( dx < 604800 ) return 2 + return 1 + } + { + if(!paths[$1]) { + times[$1] = $2 + la[$1] = $3 + paths[$1] = 1 + } else { + times[$1] += $2 + if($3 > la[$1]) la[$1] = $3 + } + } + END { + for(i in paths) printf "%-10s %s\n", '"$prior"', i + }' - 2>> "$_FASD_SINK" + ;; + + --backend) + case $2 in + native) cat "$_FASD_DATA";; + viminfo) + < "$_FASD_VIMINFO" sed -n '/^>/{s@~@'"$HOME"'@ + s/^..// + p + }' | $_FASD_AWK -v t="$(date +%s)" '{ + t -= 60 + print $0 "|1|" t + }' + ;; + recently-used) + local nl="$(printf '\\\nX')"; nl="${nl%X}" # slash newline for sed + tr -d '\n' < "$_FASD_RECENTLY_USED_XBEL" | \ + sed 's@file:/@'"$nl"'@g;s@count="@'"$nl"'@g' | sed '1d;s/".*$//' | \ + tr '\n' '|' | sed 's@|/@'"$nl"'@g' | $_FASD_AWK -F'|' '{ + sum = 0 + for( i=2; i<=NF; i++ ) sum += $i + print $1 "|" sum + }' + ;; + *) eval "$2";; + esac + ;; + + *) # parsing logic and processing + local fnd= last= _FASD_BACKENDS="$_FASD_BACKENDS" _fasd_data= comp= exec= + while [ "$1" ]; do case $1 in + --complete) [ "$2" = "--" ] && shift; set -- $2; local lst=1 r=r comp=1;; + --query|--add|--delete|-A|-D) fasd "$@"; return $?;; + --version) [ -z "$comp" ] && echo "1.0.1" && return;; + --) while [ "$2" ]; do shift; fnd="$fnd $1"; last="$1"; done;; + -*) local o="${1#-}"; while [ "$o" ]; do case $o in + s*) local show=1;; + l*) local lst=1;; + i*) [ -z "$comp" ] && local interactive=1 show=1;; + r*) local mode=rank;; + t*) local mode=recent;; + e*) o="${o#?}"; if [ "$o" ]; then # there are characters after "-e" + local exec="$o" # anything after "-e" + else # use the next argument + local exec="${2:?"-e: Argument needed "}" + shift + fi; break;; + b*) o="${o#?}"; if [ "$o" ]; then + _FASD_BACKENDS="$o" + else + _FASD_BACKENDS="${2:?"-b: Argument needed"}" + shift + fi; break;; + B*) o="${o#?}"; if [ "$o" ]; then + _FASD_BACKENDS="$_FASD_BACKENDS $o" + else + _FASD_BACKENDS="$_FASD_BACKENDS ${2:?"-B: Argument needed"}" + shift + fi; break;; + a*) local typ=e;; + d*) local typ=d;; + f*) local typ=f;; + R*) local r=r;; + [0-9]*) local _fasd_i="$o"; break;; + h*) [ -z "$comp" ] && echo "fasd [options] [query ...] +[f|a|s|d|z] [opions] [query ...] + options: + -s list paths with scores + -l list paths without scores + -i interactive mode + -e set command to execute on the result file + -b only use backend + -B add additional backend + -a match files and directories + -d match directories only + -f match files only + -r match by rank only + -t match by recent access only + -R reverse listing order + -h show a brief help message + -[0-9] select the nth entry + +fasd [-A|-D] [paths ...] + -A add paths + -D delete paths" >&2 && return;; + esac; o="${o#?}"; done;; + *) fnd="$fnd $1"; last="$1";; + esac; shift; done + + # guess whether the last query is selected from tab completion + case $last in + /?*) if [ -z "$show$lst" -a -${typ:-e} "$last" -a "$exec" ]; then + $exec "$last" + return + fi;; + esac + + local R; [ -z "$r" ] && R=r || R= # let $R be the opposite of $r + fnd="${fnd# }" + + local res + res="$(fasd --query 2>> "$_FASD_SINK")" # query the database + [ $? -gt 0 ] && return + if [ 0 -lt ${_fasd_i:-0} ] 2>> "$_FASD_SINK"; then + res="$(printf %s\\n "$res" | sort -n${R} | \ + sed -n "$_fasd_i"'s/^[^ ]*[ ]*//p')" + elif [ "$interactive" ] || [ "$exec" -a -z "$fnd$lst$show" -a -t 1 ]; then + if [ "$(printf %s "$res" | sed -n '$=')" -gt 1 ]; then + res="$(printf %s\\n "$res" | sort -n${R})" + printf %s\\n "$res" | sed = | sed 'N;s/\n/ /' | sort -nr >&2 + printf "> " >&2 + local i; read i; [ 0 -lt "${i:-0}" ] 2>> "$_FASD_SINK" || return 1 + fi + res="$(printf %s\\n "$res" | sed -n "${i:-1}"'s/^[^ ]*[ ]*//p')" + elif [ "$lst" ]; then + [ "$res" ] && printf %s\\n "$res" | sort -n${r} | sed 's/^[^ ]*[ ]*//' + return + elif [ "$show" ]; then + [ "$res" ] && printf %s\\n "$res" | sort -n${r} + return + elif [ "$fnd" ] && [ "$exec" -o ! -t 1 ]; then # exec or subshell + res="$(printf %s\\n "$res" | sort -n | sed -n '$s/^[^ ]*[ ]*//p')" + else # no args, show + [ "$res" ] && printf %s\\n "$res" | sort -n${r} + return + fi + if [ "$res" ]; then + fasd --add "$res" + [ -z "$exec" ] && exec='printf %s\n' + $exec "$res" + fi + ;; + esac +} + +fasd --init env + +case $- in + *i*) ;; # assume being sourced, do nothing + *) # assume being executed as an executable + if [ -x "$_FASD_SHELL" -a -z "$_FASD_SET" ]; then + _FASD_SET=1 exec $_FASD_SHELL "$0" "$@" + else + fasd "$@" + fi;; +esac + diff --git a/bin/long-running.bash b/bin/long-running.bash new file mode 100644 index 0000000..5b88110 --- /dev/null +++ b/bin/long-running.bash @@ -0,0 +1,108 @@ +# Copyright (c) 2008-2012 undistract-me developers. See LICENSE for details. +# +# Source this, and then run notify_when_long_running_commands_finish_install +# +# Relies on http://www.twistedmatrix.com/users/glyph/preexec.bash.txt + +# Generate a notification for any command that takes longer than this amount +# of seconds to return to the shell. e.g. if LONG_RUNNING_COMMAND_TIMEOUT=10, +# then 'sleep 11' will always generate a notification. + +# Default timeout is 10 seconds. +if [ -z "$LONG_RUNNING_COMMAND_TIMEOUT" ]; then + LONG_RUNNING_COMMAND_TIMEOUT=10 +fi + +# The pre-exec hook functionality is in a separate branch. +if [ -z "$LONG_RUNNING_PREEXEC_LOCATION" ]; then + LONG_RUNNING_PREEXEC_LOCATION=$HOME/bin/preexec.bash +fi + +if [ -f "$LONG_RUNNING_PREEXEC_LOCATION" ]; then + . $LONG_RUNNING_PREEXEC_LOCATION +else + echo "Could not find preexec.bash" +fi + + +function notify_when_long_running_commands_finish_install() { + + function active_window_id () { + if [[ -n $DISPLAY ]] ; then + set - $(xprop -root _NET_ACTIVE_WINDOW) + echo $5 + return + fi + echo nowindowid + } + + function sec_to_human () { + local H='' + local M='' + local S='' + + local h=$(($1 / 3600)) + [ $h -gt 0 ] && H="${h} hour" && [ $h -gt 1 ] && H="${H}s" + + local m=$((($1 / 60) % 60)) + [ $m -gt 0 ] && M=" ${m} min" && [ $m -gt 1 ] && M="${M}s" + + local s=$(($1 % 60)) + [ $s -gt 0 ] && S=" ${s} sec" && [ $s -gt 1 ] && S="${S}s" + + echo $H$M$S + } + + function precmd () { + + if [[ -n "$__udm_last_command_started" ]]; then + local now current_window + + printf -v now "%(%s)T" -1 + current_window=$(active_window_id) + if [[ $current_window != $__udm_last_window ]] || + [[ $current_window == "nowindowid" ]] ; then + local time_taken=$(( $now - $__udm_last_command_started )) + local time_taken_human=$(sec_to_human $time_taken) + local appname=$(basename "${__udm_last_command%% *}") + if [[ $time_taken -gt $LONG_RUNNING_COMMAND_TIMEOUT ]] && + [[ -n $DISPLAY ]] && + [[ ! " $LONG_RUNNING_IGNORE_LIST " == *" $appname "* ]] ; then + local icon=dialog-information + local urgency=low + if [[ $__preexec_exit_status != 0 ]]; then + icon=dialog-error + urgency=normal + fi + notify=$(command -v notify-send) + if [ -x "$notify" ]; then + $notify \ + -i $icon \ + -u $urgency \ + "Long command completed" \ + "\"$__udm_last_command\" took $time_taken_human" + else + echo -ne "\a" + fi + fi + if [[ -n $LONG_RUNNING_COMMAND_CUSTOM_TIMEOUT ]] && + [[ -n $LONG_RUNNING_COMMAND_CUSTOM ]] && + [[ $time_taken -gt $LONG_RUNNING_COMMAND_CUSTOM_TIMEOUT ]] ; then + # put in brackets to make it quiet + export __preexec_exit_status + ( $LONG_RUNNING_COMMAND_CUSTOM \ + "\"$__udm_last_command\" took $time_taken_human" & ) + fi + fi + fi + } + + function preexec () { + # use __udm to avoid global name conflicts + __udm_last_command_started=$(printf "%(%s)T\n" -1) + __udm_last_command=$(echo "$1") + __udm_last_window=$(active_window_id) + } + + preexec_install +} diff --git a/bin/preexec.bash b/bin/preexec.bash new file mode 100644 index 0000000..df21d44 --- /dev/null +++ b/bin/preexec.bash @@ -0,0 +1,180 @@ +# Copyright (c) 2008-2012 undistract-me developers. See LICENSE for details. +# +# preexec.bash -- Bash support for ZSH-like 'preexec' and 'precmd' functions. + +# The 'preexec' function is executed before each interactive command is +# executed, with the interactive command as its argument. The 'precmd' +# function is executed before each prompt is displayed. + +# To use, in order: + +# 1. source this file +# 2. define 'preexec' and/or 'precmd' functions (AFTER sourcing this file), +# 3. as near as possible to the end of your shell setup, run 'preexec_install' +# to kick everything off. + +# Note: this module requires 2 bash features which you must not otherwise be +# using: the "DEBUG" trap, and the "PROMPT_COMMAND" variable. preexec_install +# will override these and if you override one or the other this _will_ break. + +# This is known to support bash3, as well as *mostly* support bash2.05b. It +# has been tested with the default shells on MacOS X 10.4 "Tiger", Ubuntu 5.10 +# "Breezy Badger", Ubuntu 6.06 "Dapper Drake", and Ubuntu 6.10 "Edgy Eft". + + +# Copy screen-run variables from the remote host, if they're available. + +if [[ "$SCREEN_RUN_HOST" == "" ]] +then + SCREEN_RUN_HOST="$LC_SCREEN_RUN_HOST" + SCREEN_RUN_USER="$LC_SCREEN_RUN_USER" +fi + +# Default do-nothing implementation of preexec. +function preexec () { + true +} + +# Default do-nothing implementation of precmd. +function precmd () { + true +} + +# This function is installed as the PROMPT_COMMAND; it is invoked before each +# interactive prompt display. It sets a variable to indicate that the prompt +# was just displayed, to allow the DEBUG trap, below, to know that the next +# command is likely interactive. +function preexec_invoke_cmd () { + precmd + trap 'preexec_invoke_exec' DEBUG +} + +# This function is installed as the DEBUG trap. It is invoked before each +# interactive prompt display. Its purpose is to inspect the current +# environment to attempt to detect if the current command is being invoked +# interactively, and invoke 'preexec' if so. +function preexec_invoke_exec () { + if [[ -n "$COMP_LINE" ]] + then + # We're in the middle of a completer. This obviously can't be + # an interactively issued command. + return + fi + trap '' DEBUG + + if [[ "preexec_invoke_cmd" == "$BASH_COMMAND" ]] + then + # Sadly, there's no cleaner way to detect two prompts being displayed + # one after another. This makes it important that PROMPT_COMMAND + # remain set _exactly_ as below in preexec_install. Let's switch back + # out of interactive mode and not trace any of the commands run in + # precmd. + + # Given their buggy interaction between BASH_COMMAND and debug traps, + # versions of bash prior to 3.1 can't detect this at all. + return + fi + + # In more recent versions of bash, this could be set via the "BASH_COMMAND" + # variable, but using history here is better in some ways: for example, "ps + # auxf | less" will show up with both sides of the pipe if we use history, + # but only as "ps auxf" if not. + local this_command=`HISTTIMEFORMAT= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`; + + # If none of the previous checks have earlied out of this function, then + # the command is in fact interactive and we should invoke the user's + # preexec hook with the running command as an argument. + preexec "$this_command" +} + +function preexec_set_exit () { + __preexec_exit_status=$? +} + +# Execute this to set up preexec and precmd execution. +function preexec_install () { + + # *BOTH* of these options need to be set for the DEBUG trap to be invoked + # in ( ) subshells. This smells like a bug in bash to me. The null stderr + # redirections are to quiet errors on bash2.05 (i.e. OSX's default shell) + # where the options can't be set, and it's impossible to inherit the trap + # into subshells. + + set -o functrace > /dev/null 2>&1 + shopt -s extdebug > /dev/null 2>&1 + + # Finally, install the actual traps. + if [ -n "$PROMPT_COMMAND" ]; then + PROMPT_COMMAND="preexec_set_exit;${PROMPT_COMMAND};preexec_invoke_cmd"; + else + PROMPT_COMMAND="preexec_set_exit;preexec_invoke_cmd"; + fi +} + +# Since this is the reason that 99% of everybody is going to bother with a +# pre-exec hook anyway, we'll include it in this module. + +# Change the title of the xterm. +function preexec_xterm_title () { + local title="$1" + echo -ne "\033]0;$title\007" > /dev/stderr +} + +function preexec_screen_title () { + local title="$1" + echo -ne "\033k$1\033\\" > /dev/stderr +} + +# Abbreviate the "user@host" string as much as possible to preserve space in +# screen titles. Elide the host if the host is the same, elide the user if the +# user is the same. +function preexec_screen_user_at_host () { + local RESULT="" + if [[ "$SCREEN_RUN_HOST" == "$SCREEN_HOST" ]] + then + return + else + if [[ "$SCREEN_RUN_USER" == "$USER" ]] + then + echo -n "@${SCREEN_HOST}" + else + echo -n "${USER}@${SCREEN_HOST}" + fi + fi +} + +function preexec_xterm_title_install () { + # These functions are defined here because they only make sense with the + # preexec_install below. + function precmd () { + preexec_xterm_title "${TERM} - ${USER}@${SCREEN_HOST} `dirs -0` $PROMPTCHAR" + if [[ "${TERM}" == screen ]] + then + preexec_screen_title "`preexec_screen_user_at_host`${PROMPTCHAR}" + fi + } + + function preexec () { + preexec_xterm_title "${TERM} - $1 {`dirs -0`} (${USER}@${SCREEN_HOST})" + if [[ "${TERM}" == screen ]] + then + local cutit="$1" + local cmdtitle=`echo "$cutit" | cut -d " " -f 1` + if [[ "$cmdtitle" == "exec" ]] + then + local cmdtitle=`echo "$cutit" | cut -d " " -f 2` + fi + if [[ "$cmdtitle" == "screen" ]] + then + # Since stacked screens are quite common, it would be nice to + # just display them as '$$'. + local cmdtitle="${PROMPTCHAR}" + else + local cmdtitle=":$cmdtitle" + fi + preexec_screen_title "`preexec_screen_user_at_host`${PROMPTCHAR}$cmdtitle" + fi + } + + preexec_install +} diff --git a/bin/tmux-pwn b/bin/tmux-pwn new file mode 100755 index 0000000..4212643 --- /dev/null +++ b/bin/tmux-pwn @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + + +tmux list-clients | sed "s|^\(/dev/ttys[0-9]\+\).*\[\([0-9]\+x[0-9]\+\).*$|\2 \1|" | sort -r -n | tail -n +2 | cut -d " " -f 2 | xargs -n 1 tmux detach-client -t diff --git a/bin/undistract-me.sh b/bin/undistract-me.sh new file mode 100755 index 0000000..385bbf0 --- /dev/null +++ b/bin/undistract-me.sh @@ -0,0 +1,7 @@ +# Copyright (c) 2008-2012 undistract-me developers. See LICENSE for details. +# +# Check for interactive bash and that we haven't already been sourced. +[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$last_command_started_cache" ] && return + +. $HOME/bin/long-running.bash +notify_when_long_running_commands_finish_install