cleanup related to truncpwd, removing a bunch of unused junk from bash functions

This commit is contained in:
Dan Buch 2012-04-10 01:00:30 -04:00
parent c4412f7a15
commit f67b424570
3 changed files with 5 additions and 119 deletions

View File

@ -1,33 +1,3 @@
function home_as_tilde(){
echo $1 | sed "s@^$HOME@~@"
}
function trunc_pwd(){
if [ "$PWD" == "$HOME" ]
then
echo "~"
else
parts=($(echo $PWD | tr " " "_" | tr "/" "\n"))
parts_len="${#parts[*]}"
max_parts="4"
if [ $parts_len -le $max_parts ]
then
home_as_tilde $PWD
else
startslice=$(expr $parts_len - $max_parts)
out=""
for p in ${parts[@]:$startslice}
do
out="$out$p/"
done
echo ">" `home_as_tilde "$out" | sed "s@/\\\$@@"`
fi
fi
}
function __available_projects(){
/bin/ls $HOME/src | tr " " "\n"
}
@ -79,29 +49,6 @@ complete -F __proj_activate_comp -o default a
complete -F __proj_deactivate_reactivate_comp -o default d r
_CRUFTY_CRAP=(
'.*\.pyc$'
'.*~$'
'.*\.[^.]*\.bak$'
)
function decruft(){
local here_files=( "$(/bin/ls $PWD)" )
for fname in ${here_files[*]}
do
for pattern in ${_CRUFTY_CRAP[*]}
do
if [ -n "$(echo $fname | grep -E "$pattern")" ]
then
[ -n "$DEBUG" ] && echo "removing $fname"
rm -f "$fname"
fi
done
done
}
# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found ]; then
command_not_found_handle(){
@ -173,33 +120,6 @@ function top_commands(){
}
function svn_clean(){
for f in `svn status | grep ^?` ; do
name="`echo $f | sed \"s/\? *//\"`" ;
name="`echo $name | sed \"s/ //g\"`" ;
if [ -n "$name" ] ; then
cmd="rm -rf $name ";
echo "# ---> $cmd"
eval $cmd
fi
done
}
function hg_clean(){
find -name \*.orig -exec rm -v {} \;
find -name \*.rej -exec rm -v {} \;
unknown="$(hg status | awk '/^\?/ { print $2 }')"
test -n "$unknown" && rm -v "$unknown"
}
function svn_conflicts(){
svn status | grep -E '^!? *C'
}
function rss_pid_command(){
cmd="ps -o rss,pid,command U $USER"
if [ -n "$1" ] ; then
@ -222,48 +142,15 @@ function exit_status() {
function precmd(){
last_status=$?
PS1="\[\033[1;32m\]\u@\h\[\033[00m\]:\[\033[1;32m\]"
PS1="$PS1$(trunc_pwd)\[\033[00m\] "
local pcla="$(which print-color-loadavg 2>/dev/null)"
test -n "$pcla" && test -x $pcla && PS1="$PS1-$(print-color-loadavg)- "
PS1="$PS1$(truncpwd)\[\033[00m\] -$(print-color-loadavg)- "
PS1="$PS1$(__git_ps1 "(%s)")\n$(exit_status $last_status) "
if [ -n "$1" ]
then
echo "$PS1"
else
export PS1
fi
export PS1
}
function __git_branch_and_description(){
([[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] || \
[[ "$(git rev-parse --is-inside-git-dir 2>/dev/null)" == "true" ]]) && (
echo -n $(git branch 2>/dev/null | grep '*' | awk '{ print $2 }')
desc=$(cat $(git rev-parse --git-dir)/description | grep -v '^Unnamed repository')
test -n "$desc" && echo " \[\033[32m\]$desc\[\033[00m\]"
)
}
function make_pythonpath_local_only(){
export PYTHONPATH="$(
echo $PYTHONPATH | tr ":" "\n" | sort | uniq | \
grep -v -E '/(usr|var)' | grep -v '^$' | tr "\n" ":"
)"
}
function svn_list_unknown(){
svn st | awk '/^?/ { gsub(/^? */, "", $0) ; print $0 }'
}
function svn_add_unknown(){
svn add $(svn_list_unknown)
}
function unhyphenate(){
ruby -e "puts '$1'.gsub(/[\-_]/, ' ')"
}

View File

@ -76,8 +76,7 @@ PATH="$PATH:$FLEX_HOME/bin:$FLASHPLAYER_HOME/bin"
PATH="$PATH:/opt/java/bin"
PATH="$HOME/.rbenv/bin:$PATH"
export PATH
export PS1="%m %d %# "
export PROMPT_COMMAND='PS1=$(precmd yup)'
export PROMPT_COMMAND='precmd'
export PS2=">>> "
PYTHONPATH="$HOME/lib/python2.6/site-packages:$PYTHONPATH"

2
zshrc
View File

@ -9,5 +9,5 @@ compinit
export PS1="\$ "
function precmd() {
echo "$USER@$HOST:$PWD"
echo "$USER@$HOST:$(truncpwd)"
}