Par*_*lor 10
使用Iterm2时,如果要在与当前选项卡通过相同的目录中打开新选项卡⌘T,则可以在首选项下的配置文件中设置一个选项.
从iTerm2主菜单:
Iterm2 -> Preferences -> profiles -> working directory -> Reuse Previous Session Directory
如果你使用 ZSH 你可以尝试这样的事情;
function tab() {
local command="cd \\\"$PWD\\\"; clear; "
(( $# > 0 )) && command="${command}; $*"
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 bash,我不确定等效的是什么。此外,如果您使用 prezto 或 Oh-My-ZSH,选项卡功能已经内置。
更新
看过 prezto 是如何做到的,这应该是完整的解决方案
local command="cd \\\"$PWD\\\""
(( $# > 0 )) && command="${command}; $*"
the_app=$(
osascript 2>/dev/null <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
[[ "$the_app" == 'iTerm' ]] && {
osascript 2>/dev/null <<EOF
tell application "iTerm"
set current_terminal to current terminal
tell current_terminal
launch session "Default Session"
set current_session to current session
tell current_session
write text "${command}"
end tell
end tell
end tell
EOF
}
Run Code Online (Sandbox Code Playgroud)
它使用 AppleScript 的 CLI,似乎对我来说工作得很好。
| 归档时间: |
|
| 查看次数: |
1878 次 |
| 最近记录: |