Hacker News new | ask | show | jobs
by orthecreedence 2023 days ago
I got sick of opening the same tmux/terminal format every time I had to restart, so I wrote this:

    #!/bin/bash
    
    function command() {
            CMD="$1"
            xdotool type "$1"
            xdotool key Return
    }
    
    function key() {
            KEY="$1"
            xdotool key $KEY
    }
    
    function clear() {
            for n in {1..10}; do
                    key BackSpace
            done
    }
    
    function name_panel() {
            NAME="$1"
            key ctrl+a
            key comma
            clear
            command $NAME
    }
    
    name_panel 'cmd'
    
    key ctrl+a
    key c
    name_panel 'srv'
    
    key ctrl+a
    key c
    name_panel 'make'
    
    key ctrl+a
    key n
    
    echo "Now type ssh-add to log in..."
    ssh-agent bash
2 comments

there's a tmux plugin to restore a session you save; https://github.com/tmux-plugins/tmux-resurrect
I feel like I should point out that tmux is quite happy to take commands directly on the command line: `tmux new-window -n srv` will make a new window named "srv", `tmux next-window` will move you forward one window, etc. Hit prefix-? to list the commands bound to each key when you're running.
Thanks! I had this strange feeling someone was going to tell me something exactly like this after I posted. I'm glad I did though, it's good to learn new things.
:)

Remember, just because someone tells you a better doesn't mean there was anything wrong with your way (if nothing else, sending actual keystrokes is a universal-ish API rather than having to learn each program's specific interface, if they even have one). But yeah, knowledge-sharing is a perk of these threads, too:)