Last active
August 29, 2015 14:10
-
-
Save freayd/da7159d6d9463b61362b to your computer and use it in GitHub Desktop.
Bash / VIM private mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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