Send tmux command to tmuxinator - command

Specifically, I need to create a profile that by default will have a small pain displaying the clock, which can be triggered with C-b t. However, I couldn't find the way to do that.
In this GitHub issue comment, a Collaborator of the project said it could be defined like a regular command, but on my ZSH setup, it just didn't work, saying "zsh: Command not found: C-b".
Does anyone happen to know how I can achieve this?
Thanks!!!

windows:
- work:
panes:
- tmux clock-mode
- ipython
Below is what happens when typing tmux clock-mode inside tmux session:
current tmux client connect to tmux server
attach to current(or the most recently) session
since the -t argument is omitted, the currently active pane in the current window is used for the clock-mode command.
Checkout the session in $man tmux for more detail.
COMMANDS
This section contains a list of the commands supported by tmux. Most commands accept the optional -t argument with one of target-client, target-session
target-window, or target-pane. These specify the client, session, window or pane which a command should affect. target-client is the name of the pty(7)
file to which the client is connected, for example either of /dev/ttyp1 or ttyp1 for the client attached to /dev/ttyp1. If no client is specified, the
current client is chosen, if possible, or an error is reported. Clients may be listed with the list-clients command.

Related

Can a command be send to VSCode, directly from the integrated terminal (integrated terminal -> VSCode API)?

Hi I would like to know whether one could call a VSCode command from the integrated terminal. So basically is the terminal aware of VSCode and can they communicate (at least from terminal => VSCode)
My Usecase: I would like to have H and L, to move to editor tab left / right of the terminal (I am using the terminal in an editor tab). Additionally, I would like that to happen when I am in vim normal mode in my zsh.
So I would like, when I am in normal mode and press H that the terminal sends an editor.tabNext (or whatever the command is) to VSCode.
I think I found a workaround at least. There is an extension called Remote Control (https://marketplace.visualstudio.com/items?itemName=eliostruyf.vscode-remote-control&ssr=false#review-details), with which I can send arbitrary commands to VSCode, so this seems to work. Proabably natively this is not possible, but maybe someone knows something.
EDIT1:
Here is my setup now:
if [ ! -z $VSCODE ]; then
_sendcmd() { echo "{ \"command\": \"workbench.action.$1\" }" | websocat ws://localhost:4242 }
# define commands and register them in zsh
editor_left() { _sendcmd previousEditor }; zle -N editor_left;
editor_right() { _sendcmd nextEditor }; zle -N editor_right;
bindkey -a H editor_left
bindkey -a L editor_right
fi
where $VSCODE is defined in VSCode through terminal.integrated.env = { "VSCODE": "1" }. May this make you as happy as it makes me happy.
Yes you can do this but it will require writing a simple extension and there is one flaw with it.
If you write a VSCode extension there is an API that will set environment variables in new terminals.
export function activate(context: ExtensionContext) {
...
context.environmentVariableCollection.replace("REMOTE_CONTROLL_EXTENSION_IPC_PATH", ipcPath);
What you do is create a Unix socket (or named pipe on Windows) and pass it into that environment variable. Then in your shell you can just send data to that socket.
This is much better than the approach used by the Remote Control extension that Dimfred mentioned - it's more secure and doesn't rely on known fixed ports, which means you're going to run into issues e.g. if they don't get closed properly or you run multiple copies of VSCode.
The only downside I've found with this approach is that if restart VSCode, then the socket will be closed but VSCode will try to restore shell sessions. Those shell sessions will be left with an old REMOTE_CONTROLL_EXTENSION_IPC_PATH value which points at a non-existent socket.
I'm not sure of a way around that yet.
Edit: Actually all you need to do is ensure your Unix socket path is tied to a workspace. At least this is what the built in Git extension does. See createIPCServer(). It uses storagePath which is specific to a workspace. It also unlinks the socket at that path (if any) when it starts.
I initially thought that might cause issues if you open the same workspace twice in two windows, but VSCode won't let you do that.

Configure binding to perform predefined search in Tmux

I'm trying to find a way to jump to the previous prompt in iTerm using tmux. Can I set a binding to search a unique phrase within my prompt?
So to expand on Yuriy's answer. Inside your terminal you can run the following commands:
tmux copy-mode ; tmux send -X search-backward 'Example'
That should put your current tmux pane into copy-mode and then initiate a search for 'Example'. Now instead of typing that every time we want to search we'll create a shell script(lets say /tmp/search.sh) and then a tmux binding to that script
Contents of /tmp/search.sh
#!/usr/bin/env bash
tmux copy-mode ; tmux send -X search-backward 'These'
make sure you make it executable with chmod +x /tmp/search.sh. At this point you can test that it works by simply calling the script from your tmux session. To add it as a binding you can something akin to the following to your ~/.tmux.conf file:
bind p run-shell "bash /tmp/search.sh"
Make sure you source refresh the configuration in your tmux session and your new binding should initiate the search.
The canonical way of doing this is write a bash script to issue the commands back to your tmux.
But I'd like to suggest a mod that allows way more flexible scripting: http://ershov.github.io/tmux/ (I'm the author)
Using this mod, your problem can be solved this way:
bind p copy-mode ";" tcl {
set s [copy-mode-screenline -ex [copy-mode-get-cx]]
cursor-up
send-keys "?" "\x15$s"
}
This will read the current line from the beginning up to the cursor position and search for the previous occurrence of it.
The key 'p' can be changed to your preference.

ssh agent started but can't connect to authentication agent

I'm trying to add a new ssh key. I've started the service using "ssh-agent -s", and I get this response:
SSH_AUTH_SOCK=/tmp/ssh-tUlzwbxYNLaZ/agent.9516; export SSH_AUTH_SOCK;
SSH_AGENT_PID=8992; export SSH_AGENT_PID;
echo Agent pid 8992;
But when I do "ssh-add ~/.ssh/id_rsa" I get the error "Could not open a connection to your authentication agent." Is the start command not working? I'm not sure what the output of the start command means.
The output that you show above needs to be evaluated. Very often this is done automatically by starting ssh-agent like eval `ssh-agent`. This causes
SSH_AUTH_SOCK=/tmp/ssh-tUlzwbxYNLaZ/agent.9516; export SSH_AUTH_SOCK;: the SSH_AUTH_SOCK environment variable to be set to the given value.
SSH_AGENT_PID=8992; export SSH_AGENT_PID;: the SSH_AGENT_PID environment variable to be set to the given value.
These two variables need to be set for ssh-add to be able to find the agent. If you want to evaluate them manually you can just copy those commands, paste them into your terminal or console, and hit Enter. Then try using ssh-add again.
The last line, echo Agent pid 8992;, simply prints out the ssh-agent process ID for your information.
These variables cannot be hard-coded because the socket and PID aren't predictable. Each time you start ssh-agent you need to use whatever values it prints out.
Note that these variables only get set for the current shell. So if you do it in a terminal window and then work in that window you should be fine, but if you close the window and open a new terminal it won't work anymore. Similarly if you are logged into a console, then log out and back in again.
Most modern desktop environments start ssh-agent and set the appropriate environment variables for you, so if you're using Gnome or KDE or Unity or something you shouldn't have to do this. If you are manually starting your environment or using something more bare-bones that doesn't handle this for you you should probably add eval `ssh-agent` to your X startup file, e.g. .xinitrc so that it runs before starting X.

Save PuTTY output to file from command-line

Is there any way to save the PuTTY output to a file using the command line? I know this is easily done using the GUI but in my case it has to be done automatically.
What I'm working on:
User clicks batch file -> starts PuTTY, automatically connects to my device over SSH and runs a bunch of commands -> PuTTY should save the output to a file.
The last part I can't get working. Is there any command to do this?
This can be done with putty. The answer is little late considering the time the questions was asked, however this might help someone.
In putty, using GUI, you can save sessions with logging option on, as shown below.
Enter Host Name, Name the session, Go to Logging Option in the left top corner, select all sessions, provide log file name and location, go back to Session tab, click on the save button. Done, you have saved a session.
Now open CMD and write the command as below
You are done. Every time this session is invoked, the commands and output will be logged.
Hope this helps.
The specific program putty is not designed for this. Instead use plink, a different program in the PuTTY suite,
which uses the same session settings and keys as putty but gets input from stdin and puts output to stdout,
both of which can be redirected in the usual ways. See http://the.earth.li/~sgtatham/putty/0.63/htmldoc/Chapter7.html#plink .
As mentioned in previous answer, use plink for this.
Make sure it is in your environment path, by typing
plink -V
in your console. If it returns a version number, then you know it is in environment path variables. If it doesn't, probably best to fix this first. There are plenty of good SO answers to help you with this. Failing that, use the full path to your plink.exe in the CLI command that follows.
Then use plink to open your ssh connection, with the option -v set to provide verbose output. Finally, this all needs to be piped to a log file.
The complete cli command that I use is
plink -v username#xxx.xxx.xxx.xxx > ssh-output.log 2>&1
Open up the file ssh-ouput.log to see the results.
Expanding on Dave's and Charlie's answers...
Apart from making sure plink is in the path, also check whether you have write access to local ouput file.
This is how you redirect command output from remote machine to local file with plink. In this example we store an output from man page for nfcapd:
plink joe#192.168.50.50 -pw joespassword man nfcapd > output.log 2>&1
The first time you try to access the server, it will ask you store key in cache. So make sure to access the machine at least once before:
plink joe#192.168.50.50 -pw joespassword
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
...
Store key in cache? (y/n)

How can I make emacsclient just open a window for an existing emacs daemon without opening a new file

I use an emacs daemon to preserve my emacs session even if I have to reboot the machine that I run my X server on or if I want to access the same session from a different machine. This works very well but when restoring a session I'd quite like to just run "emacsclient --create-frame --no-wait" to connect to the daemon without opening a new file. It won't let me get away without specifying a filename.
I've tried using --eval to execute a function rather than open a file but the window just goes away when the evaluation is complete.
(Emacs 23.1 via backports on Debian GNU/Linux 5.0.)
From the help provided by emacsclient, you have a few options. First, is the one mentioned already which is emacsclient -c. That will try to create a frame associated with the emacs daemon. The advantage to this is that if DISPLAY is not set, then it will open emacs in the terminal.
Which brings us to the next best option (especially if you are logging in remotely): emacsclient -t which forces emacs to open up in terminal mode even if DISPLAY is set.
Also keep in mind that you can set the display from the command-line as well. I use this often when logging in remotely from VNC. The full command would be emacsclient -d DISPLAY -c
emacsclient -c works for me.
emacsclient -n -e "(make-frame)"
The -n flag means that the emacsclient doesn't wait, and the emacs instance doesn't destroy the frame.
If you are using emacs from the command line, you might also want to consider emacsclient -t