Skip to content

Instantly share code, notes, and snippets.

@freayd
Last active August 29, 2015 14:10
Show Gist options
  • Save freayd/da7159d6d9463b61362b to your computer and use it in GitHub Desktop.
Save freayd/da7159d6d9463b61362b to your computer and use it in GitHub Desktop.
Bash / VIM private mode
function upsearch () {
dir="${PWD}"
while true
do
[[ -f "${dir}/${1}" ]] && return 0
[[ "${dir}" == '/' ]] && return 1
dir=$(dirname "${dir}")
done
}
function update_window_title() {
[[ ${1} == ${FUNCNAME} ]] && return
title="${1}"
[[ $PRIVATE == 1 ]] && title="[PRIVATE]${title:+ $title}"
echo -ne "\033]0;${title}\007"
}
alias private='unset HISTFILE && export PS1="\e[4;36m[PRIVATE]\e[m \h:\W \u\$ " && export PRIVATE=1'
alias vimprivate='( PRIVATE=1 vim ; history -d $((HISTCMD-1)) )'
PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed 's/\s*;\s*$//g')"PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'upsearch ".private" && private ; update_window_title "$(basename ${SHELL})"'
trap 'update_window_title "${BASH_COMMAND%% *}"' DEBUG
upsearch '.private' && private
if $PRIVATE == 1
set viminfo+=n/dev/null
set noswapfile
set nobackup
set laststatus=2
highlight StatusLine NONE ctermbg=LightBlue ctermfg=Black cterm=bold
highlight StatusLineNC NONE ctermbg=DarkBlue ctermfg=White cterm=NONE
set statusline=[PRIVATE]\ %<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment