ZSH:每次 cd 后自动运行 ls

标签 zsh

所以我现在已经让 ZSH 做了所有这些很酷的事情,但是如果我每次调用“cd”后都能让它隐式运行“ls -a”,那就太棒了。我认为这必须放在 .zlogin 文件或 .aliases 文件中,我只是不确定最好的解决方案是什么。想法?引用资料?

最佳答案

编辑: 查看文档(zshbuiltinscd 内置或 hook functions 的描述)后,我找到了一个更好的方法:它使用 chpwd 函数:

function chpwd() {
    emulate -L zsh
    ls -a
}

或使用chpwd_functions数组:

function list_all() {
    emulate -L zsh
    ls -a
}
chpwd_functions=(${chpwd_functions[@]} "list_all")
<小时/>

将以下内容放入 .zshrc 中:

function cd() {
    emulate -LR zsh
    builtin cd $@ &&
    ls -a
}

关于ZSH:每次 cd 后自动运行 ls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3964068/

相关文章:

string - 像 Python 中一样使用 zsh 分割字符串

Bash 不从函数中打印换行符?

bash - zsh 自动完成不工作 : _get_comp_words_by_ref:16: bad substitution

python - 从 zsh 安装 scrapy 时出错

zsh - 如何修复 oh-my-zsh 插件无法工作的问题

zsh - 让zsh兑现dircolors-solarized

shell - 具有历史记录的 zsh 绑定(bind) key

vim - 如何在 Vim 中自动完成文件路径,就像在 zsh 中一样?

bash - 如何在单行上重新运行 ZSH 中的内联循环(类似 bash 的行为)

macos - 使用并行和 mutool 拆分多个 PDF 文件