bash进阶

#~/lwtools.sh

# 使用如下命令增加进bashrc中:source ~/lwtools.sh  

# Filesystem Markers & Jump

#目录之间快速切换,很好的设计,代码转自:http://bbs.chinaunix.net/thread-4178078-1-1.html
export MARKPATH=$HOME/.marks
function jump(){
  cd -P $MARKPATH/$1 2>/dev/null || echo "No such mark: $1"
}
function mark(){
  mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1
}
function unmark(){
  rm -i $MARKPATH/$1
}
 
function _marks(){
  COMPREPLY=()
  local cur=${COMP_WORDS[COMP_CWORD]};
  local com=${COMP_WORDS[COMP_CWORD-1]};
  case $com in
    'jump')
      local marks=($(ls ${MARKPATH}))
      COMPREPLY=($(compgen -W '${marks[@]}' -- $cur))
      ;;
    'unmark')
      local marks=($(ls ${MARKPATH}))
      COMPREPLY=($(compgen -W '${marks[@]}' -- $cur))
      ;;
  esac
}
complete -F _marks jump
complete -F _marks unmark


function lwgrep(){
ps aux | grep $1 | grep -v grep | awk '{print $2}'
}


function lwkill(){
ps aux | grep $1 | grep -v grep | awk '{print $2}' | xargs kill -s 9
}


function lwps(){
ps aux | grep $1 | grep -v grep
}


export lwgrep
export lwkill
export lwps



#持续学习更新中。。。

你可能感兴趣的:(bash进阶)