Saltar al contenido

~ / archivo / stackoverflow / 50346138

Terminator initial script

StackOverflow · oh-my-zsh, terminator · ayudé
  1. Gleb pregunta +3 2018-05-15 08:59

    I'm current user of terminator & oh-my-zsh. In teminator I tried to set my custom layout with several tabs and initial commands for every tab. I followed instruction as described here https://amir.rachum.com/blog/2015/11/28/terminator-multiple-custom-commands/ Main part there is this script in .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
    

    Everything works fine except commands from initial script are not stored in my zsh history. If I execute commands directly in zsh it works properly as well. My guess is that history file loaded after my command is executed.

    • Tarun Lalwani 2018-05-27 04:57 @AmirRachum Why not just use a workaround or so? echo "$cmd" >> ~/.zsh_history
    • Gleb 2018-05-28 08:05 @TarunLalwani I've tried your way and it works but it shares $cmd among tabs
    • Tarun Lalwani 2018-05-28 08:28 Try adding a fc -R ~/.zsh_history in your init script and see if it helps
    • Tarun Lalwani 2018-05-28 15:03 Also when I test this code on mac with zsh 5.5.1 (x86_64-apple-darwin17.5.0) it works great. Please check what version of zsh you are using and see if that is the source of the problem
    • Gleb 2018-05-30 08:35 @TarunLalwani I added fc -R ~/.zsh_history command before that script, but it didn't help me. My zsh version was 5.2 on Ubuntu 17.10 and it doesn't let me upgrade it till I upgraded my Ubuntu to 18.04. Now I have zsh 5.4.2 (x86_64-ubuntu-linux-gnu) which is last stable. And the problem with shared history still exists. I noticed that my usual history stored in such way: : 1527666945:0;mc. Maybe that's my problem
  2. nemanjabu respuesta +1 2019-11-14 17:00

    Simple solution for bash

    append ;bash to you custom command

    Example: change redis-server to redis-server; bash

    • Yehor 2023-01-03 11:36 Your answer helped me, thank you very much! But could you please explain why ; bash did the trick ?
  3. Miguel Ortiz yo respuesta 2018-05-31 16:16

    The solution for this (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
    

    The solution for this (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
    

← todos los hilos de StackOverflow