3

我是终结者和 oh-my-zsh 的当前用户。在 teminator 中,我尝试使用多个选项卡和每个选项卡的初始命令设置自定义布局。我按照此处所述的说明进行操作https://amir.rachum.com/blog/2015/11/28/terminator-multiple-custom-commands/ 主要部分在 .zshrc 中有此脚本

echo $INIT_CMD
if [ ! -z "$INIT_CMD" ]; then
    OLD_IFS=$IFS
    setopt shwordsplit
    IFS=';'
    for cmd in $INIT_CMD; do
        print -s "$cmd"  # add to history
        eval $cmd
    done
    unset INIT_CMD
    IFS=$OLD_IFS
fi

除了初始脚本中的命令未存储在我的 zsh 历史记录中外,一切正常。如果我直接在 zsh 中执行命令,它也可以正常工作。我的猜测是执行我的命令后加载的历史文件。

4

2 回答 2

0

bash的简单解决方案

将;bash附加到您的自定义命令

示例:更改redis-serverredis-server; bash

于 2019-11-14T17:00:26.507 回答
0

解决方案(bash

echo $INIT_CMD
if [ ! -z "$INIT_CMD" ]; then
    OLD_IFS=$IFS
    IFS=';'
    for cmd in $INIT_CMD; do
        history -s "$cmd"  # add to history
        eval $cmd
    done
    unset INIT_CMD
    IFS=$OLD_IFS
    # ----------------required to refresh the shell session
    history -a # append history lines from this session 
               # to the history file
    history -r # read the history file and append the 
               # contents to the history list

fi

解决方案(zsh

echo $INIT_CMD
if [ ! -z "$INIT_CMD" ]; then
    OLD_IFS=$IFS
    setopt shwordsplit
    IFS=';'
    for cmd in $INIT_CMD; do
        print -S "$cmd"  # add to history
        eval $cmd
    done
    unset INIT_CMD
    IFS=$OLD_IFS
fi
于 2018-05-31T16:16:11.297 回答