2010-08-09 58 views

回答

4

不要忘记pushdpopd,除非你从不使用它们。我会这样做:

PS1='(\w) \$ ' 
chdir() { 
    local action="$1"; shift 
    case "$action" in 
     # popd needs special care not to pass empty string instead of no args 
     popd) [[ $# -eq 0 ]] && builtin popd || builtin popd "$*" ;; 
     cd|pushd) builtin $action "$*" ;; 
     *) return ;; 
    esac 
    # now do stuff in the new pwd 
    echo Your last 3 modified files: 
    ls -t | head -n 3 
} 
alias cd='chdir cd' 
alias pushd='chdir pushd' 
alias popd='chdir popd' 
+1

几乎工作.'没有参数的pushd'交换与dir堆栈的顶部.' cd'没有参数更改为$ HOME目录,代之以:'pushd | popd | cd)[[$#-eq 0]] && builtin $ action ||内置$动作“$ *”;;'。 – 2013-04-24 22:47:20

+0

这个呢? http://stackoverflow.com/a/18244439/171318 – hek2mgl 2013-08-15 00:24:05

+0

加入Charles Merriam的建议 – fuzzyTew 2015-11-14 12:20:12

3

你可以建立一个别名cd执行该标准cd,然后您已经定义了一些功能。

0
alias cd='echo DO SOME WORK; cd $*' 
+3

不,'$ *'用于函数中,而不是别名。 – 2010-08-09 20:25:35

3

使用PROMPT_COMMAND。你应该看看git-sh,其中包含了很多花哨的git相关技巧,也应该很容易学习。

+0

这也是非常有用的,但我不能标记2个东西作为答案:( 谢谢! – battlemidget 2010-08-09 20:56:39