20090504

This .bashrc should be tested a bit.

OK. I've really got to get to work. There's lots more changes. It's going to take some time using this to find out what parts are not needed, and where there's missing stuff. If you have any suggestions, I'd love to hear them.

# to be added to .bashrc
#-----------------------------------------------------------------------------
# file management and navigation

alias g="pushd"
alias b="popd"
alias gh="pushd ~"
alias gr="pushd /"
alias gd="pushd ~/documents/"
alias gm="pushd /media/disk1part3/renick/music/"
alias l='ls -a --group-directories-first | less -rn'
alias ls='ls -CF'
alias ll='ls -lahGp --color=always --group-directories-first | less -rn'
alias lst='ls -lahGpt --color=always --group-directories-first | less -rn'
alias lsd="ls -d */"
alias duh='du -h --max-depth=1 | less'
alias dus='du | sort -nr | less'
alias ..='pushd ..'
alias ...='pushd .. ; pushd ..'

# do ". acd_func.sh"
# acd_func 1.0.5, 10-nov-2004
# petar marinov, http:/geocities.com/h2428, this is public domain
# with the aliases below, type "dl" to see a directory list of recently accessed directories
# then "cd -" and the number from the menu

cd_func ()
{
local x2 the_new_dir adir index
local -i cnt

if [[ $1 == "--" ]]; then
dirs -v
return 0
fi

the_new_dir=$1
[[ -z $1 ]] && the_new_dir=$HOME

if [[ ${the_new_dir:0:1} == '-' ]]; then
#
# Extract dir N from dirs
index=${the_new_dir:1}
[[ -z $index ]] && index=1
adir=$(dirs +$index)
[[ -z $adir ]] && return 1
the_new_dir=$adir
fi

#
# '~' has to be substituted by ${HOME}
[[ ${the_new_dir:0:1} == '~' ]] && the_new_dir="${HOME}${the_new_dir:1}"

#
# Now change to the new dir and add to the top of the stack
pushd "${the_new_dir}" > /dev/null
[[ $? -ne 0 ]] && return 1
the_new_dir=$(pwd)

#
# Trim down everything beyond 11th entry
popd -n +11 2>/dev/null 1>/dev/null

#
# Remove any other occurence of this dir, skipping the top of the stack
for ((cnt=1; cnt <= 10; cnt++)); do
x2=$(dirs +${cnt} 2>/dev/null)
[[ $? -ne 0 ]] && return 0
[[ ${x2:0:1} == '~' ]] && x2="${HOME}${x2:1}"
if [[ "${x2}" == "${the_new_dir}" ]]; then
popd -n +$cnt 2>/dev/null 1>/dev/null
cnt=cnt-1
fi
done

return 0
}

alias cd=cd_func

if [[ $BASH_VERSION > "2.05a" ]]; then
# ctrl+w shows the menu
bind -x "\"\C-w\":cd_func -- ;"
fi

alias dl='cd --'

# system for making quick bookmarks
alias +1='echo ~+ > ~/.path1'
alias +2='echo ~+ > ~/.path2'
alias +3='echo ~+ > ~/.path3'
alias +4='echo ~+ > ~/.path4'
alias +5='echo ~+ > ~/.path5'
alias +6='echo ~+ > ~/.path6'
alias +7='echo ~+ > ~/.path7'
alias +8='echo ~+ > ~/.path8'
alias +9='echo ~+ > ~/.path9'
alias +0='echo ~+ > ~/.path0'
# list the bookmarks
alias bl='for i in '~/.path*'; do echo -e "\E[37;44m""$i";cat $i; done; tput sgr0'
# go to the numbered bookmark
j () { pushd "$(cat ~/.path$1)"; }

alias yp='echo ~+ > ~/.yankedpath'
alias pp='cat ~/.yankedpath'
alias G='pushd `pp`'

alias ,d='mkdir'
# move something to the previously yanked path
,m () { mv $1 `pp`; }
# copy something to the previously yanked path
,c () { cp $1 `pp`; }

# extract any archive
xx () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}

# tar a directory
alias td='tar -czvf'
# zip a directory
alias zd='zip -r'

No comments: