I have the following script:
#!/bin/sh
tmux new-session -d -s vim 'vim index.js'
tmux split-window -h 'nodemon index.js'
tmux -2 attach-session -d
My goal is to have a tmux session open with vim in left pane and nodemon running in the right. This seems to start up fine, but then stops and the right pane closes after a few seconds.
Additionally I'd like to have it set the cursor in the left pane on start.
Any help would be greatly appreciated.
Problem is that you have bound pane to a command. Which means when you close command the pane will close too. Use different approach. Open pane and then send-keys to open desired command
#!/bin/sh
tmux new-session -d -s vim
tmux send-keys -t vim:.1 'vim index.js' Enter
tmux split-window -h
tmux send-keys -t vim:.2 'nodemon index.js' Enter
# select pane
tmux select-pane -t vim:.2
tmux -2 attach-session -d
Note: Also you could look into https://github.com/tmuxinator/tmuxinator
Related
Maybe about a week or so ago I noticed a weird problem when I use the Remote SSH Extension with tmux. After opening a terminal and starting tmux the following is printed to the console after every command:
-bash: __vsc_prompt_cmd_original: command not found
If I check the Log (Remote Pty Host) section of the Output tab I see the following:
[2022-08-19 14:48:23.822] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/sh" and args ["-c","wget --version > /dev/null\nif [ $? -eq 0 ]\nthen\n\twget --connect-timeout=7 --tries=1 --dns-timeout=7 -q --header='Metadata:true' -O - http://169.254.169.254/metadata/instance?api-version=2019-03-11\nelse\n\tcurl --version > /dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tcurl --connect-timeout 7 -s --header='Metadata:true' http://169.254.169.254/metadata/instance?api-version=2019-03-11\n\tfi\nfi\nexit 0"]
[2022-08-19 14:48:23.890] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/sh" and args ["-c","wget --version > /dev/null\nif [ $? -eq 0 ]\nthen\n\twget --connect-timeout=7 --tries=1 --dns-timeout=7 -q -O - http://169.254.169.254/latest/meta-data/instance-id\nelse\n\tcurl --version > /dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tcurl --connect-timeout 7 -s http://169.254.169.254/latest/meta-data/instance-id\n\tfi\nfi\nexit 0"]
[2022-08-19 14:48:23.896] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/sh" and args ["-c","wget --version > /dev/null\nif [ $? -eq 0 ]\nthen\n\twget --connect-timeout=7 --tries=1 --dns-timeout=7 -q -O - http://169.254.169.254/metadata/v1/id\nelse\n\tcurl --version > /dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tcurl --connect-timeout 7 -s http://169.254.169.254/metadata/v1/id\n\tfi\nfi\nexit 0"]
[2022-08-19 14:48:23.900] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/sh" and args ["-c","wget --version > /dev/null\nif [ $? -eq 0 ]\nthen\n\twget --connect-timeout=7 --tries=1 --dns-timeout=7 -q --header='Metadata-Flavor:Google' -O - http://metadata.google.internal/computeMetadata/v1/instance/id\nelse\n\tcurl --version > /dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tcurl --connect-timeout 7 -s --header='Metadata-Flavor:Google' http://metadata.google.internal/computeMetadata/v1/instance/id\n\tfi\nfi\nexit 0"]
[2022-08-19 14:52:08.838] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/tmux" and args undefined
The last line seems concerning, and if I use the Remote SSH extension for a different host (where tmux works) that line does not appear (leading me to believe the behavior is potentially connected).
Both remote hosts have terminal integration enabled (and disabling terminal integration doesn't seem to do anything). Looking in the settings for VSCode terminal integration, I noticed that tmux is not listed as a supported shell for terminal integration (only bash, pwsh, and zsh are). I also see a warning that a complex bash PROMPT_COMMAND might also break things (and I have edited my PS1 to print the github branch I'm on, though that works on the other remote host just fine). The link in the settings (which I've reproduced here) is busted, there's no #_complex-bash-promptcommand anchor on that page so that might be a red herring anyway.
Any thoughts? Should I submit a VSCode issue? Am I totally lost here?
You can test the following method.
Using an editor such as nano or vim, Add the line
unset PROMPT_COMMAND
to your .bashrc file, and it will take effect on the next session.
To apply the change immediately for the life of the current shell session, type
unset PROMPT_COMMAND
in your terminal window.
I have a function that is basically a wrapper around a tmux subcommand:
function tma() {
tmux attach-session -t $1 || tmux new-session -s $1
}
I would like zsh to autocomplete with any open sessions that may exists as it currently does if I type tmux attach-session -t and start tabbing. I've tried
compdef tma=tmux
which understandably tries to autocomplete to tmux subcommands and
compdef tma=tmux attach-session -t
which gives the error message compdef: unknown command or service: tmux attach-session -t.
Is this possible?
I needed to get the fingerprint of a ssh key using:
$ ssh-keygen -lf ~/.ssh/id_rsa_user.pub
after typing:ssh-keygen -lf ~/.ss TAB It was not giving any options.
I had to do:
$ compdef _files ssh-keygen
After that I was available to autocomplete using the files path, but the command autocomplete stop working, so if if I type ssh-keygen - Tab I don't see any more this output:
$ ssh-keygen -
-- option --
-B -- show the bubblebabble digest of key
-C -- provide new comment
-D -- download key stored in smartcard reader
-N -- provide new passphrase
-P -- provide old passphrase
-U -- upload key to smartcard reader
-b -- specify number of bits in key
-c -- change comment in private and public key files
-e -- export key to SECSH file format
-f -- key file
-i -- import key to OpenSSH format
-l -- show fingerprint of key file
-p -- change passphrase of private key file
-q -- silence ssh-keygen
-t -- specify the type of the key to create
-y -- get public key from private key
So wondering if there is a way of having both options enabled so that I can do something like:
ssh-keyg TAB that will give me:
$ ssh-keygen
Then I can do
$ ssh-keygen - TAB
That would print the option menu and been available to do:
$ ssh-keygen -lf ~/.ss TAB
And have list of options what could work so at the end I would get something like:
$ ssh-keygen -lf ~/.ssh/id_rsa_user.pub
For now I just add to my ~/.zshrc this:
compdef _files ssh-keygen
compdef _files adb
compdef _files mysql
...
But I have to do that for avery command I want to use the _files completion, therefore I would like to know if there is a way to always use _files or failover to it.
Any ideas?
Could it be possible to make it behave like csh in where pressing Ctrl+d shows files options?
Update:
I notice that if I the last argument is an -f the autocomplete works:
ssh-keygen -l -f ~/.sshTAB
But for custom scripts, commands what function, widget alias could help do force the _files completion.?
The solution was to update to zsh this is how I did it:
# check the zsh info
brew info zsh
# install zsh
brew install zsh
# add shell path
sudo vim /etc/shells
# add the following line into the very end of the file(/etc/shells)
/usr/local/bin/zsh
# change default shell
chsh -s /usr/local/bin/zsh
I had issues completing git-flow this was fixed by reinstalling with --without-completions:
$ brew install git --without-completions
I'm working on small script that is interactive. I'm trying to start tmux both specifying the command (so that when the process exits the tmux session exits) and using a configuration file - but it doesn't appear that this is possible.
tmux new-session -d -s myapp 'python myapp.py' -f 'myapp-tmux.conf'
Any ideas?
You need to move the -f … to before new-session. It is an argument for tmux itself; the new-session (sub)command does not understand or accept -f.
Also, the configuration file (~/.tmux.conf, or the one specified with -f) is only used when initially starting a server. If you have other (possibly detached) sessions running under the default server, then the -f … portion of your command will go unused. Check for other sessions with tmux ls.
You might want to use -L (or -S) to specify an alternate server (i.e. one where you can make sure your session is always the only one):
tmux -L myapp -f myapp-tmux.conf new-session -d -s myapp 'python myapp.py'
Later, to attach to that session:
tmux -L myapp attach -t myapp
(You may leave off -t myapp if the sever only has that one session.)
If you do want to use you existing server (so that changes made via the configuration file can affect your other sessions), then you might want to use source instead:
tmux source myapp-tmux.conf \; new-session -d -s myapp 'python myapp.py'
I am having trouble accessing Coda from command-line. I installed the "command-line coda" plug-in, verified that my installation is in the correct location, yet I still can seem to access Coda. Coda sits in my "Applications" folder which is the default location for the plug-in.
Anyone have have this problem? Any tips? On the their site it is recommended that you change the path.
export CODEPATH=/Applications/Coda.app
So I included the above line in my .bash_profile which did not help.
$ Coda -v
-bash: Coda: command not found
Thanks for any direction you can provide.
The default way to open an application on a Mac is to use open -a AppName so you should be able to change your bash profile to use that:
$ open -a Coda
I've created a bash script (as opposed to using the plugin) that Gregory Tomlinson originally posted about (it looks like he's since taken it down but it looks like the following).
Create a new file in /bin called coda:
$ cd /bin
$ sudo touch coda
$ vim coda
Hit an i to enter insert mode. Then include the following code:
#! /bin/bash
if [ "$1" = "" ]; then
echo "Please specify a file to open or create"
exit 0
else
for ARG in $*
do
touch -a $ARG && open -a Coda $ARG
done
exit 0
fi
Save and quit (hit the esc to exit insert mode then type :w !sudo tee % >/dev/null followed by the return key, press L for load when prompted, then type :q to quit). Then give that file execute permissions:
$ chmod u+x coda
Start a new Terminal window and you should be able to use:
$ coda filename.foo
Or just:
$ coda
For some strange reason, my paid registered Coda 2 app just wouldn't open for me this morning. I found this terminal command that worked for me:
open -a Coda\ 2
You can also put the following in your ~/.bash_profile file:
alias coda='open -a "Coda 2"'
I had a similar problem. After installing the plug-in, I still couldn't launch coda from the command line. I took a closer look at /user/local/bin and somehow the permissions had gotten reset so I didn't have execute permissions for /user/local/bin.
I updated my permissions with:
sudo chmod o=rx,g=rx /usr/local/bin
This solved my problem. However, Coda won't launch if the specified file does not exist, which makes it hard to create a file from the command line.