Tmux does not work - tmux

I created many sessions in tmux and closed them all with one comand:
pkill -f tmux
Unfortunately, now when I create new session via
tmux new -s alex
And get the following error:
sessions should be nested with care, unset $TMUX to force
Tell me please how can I solve this problem?

This message indicates that you are still in a session attach.
For example, you can check:
salio#salios ~ % tmux ls
1: 1 windows (created Fri Jan 13 16:38:10 2023)
3: 1 windows (created Fri Jan 13 21:12:34 2023) (attached)
4: 1 windows (created Fri Jan 13 22:49:13 2023)
6: 2 windows (created Fri Jan 13 23:05:50 2023)
I am currently attached to session 3
If I run the following command, I get an error:
tmux attach-session -t <Favorite session>
sessions should be nested with care, unset $TMUX to force
So, first of this session, dis-attach with the command ‍Ctrl+b+d
Now use the following command:
tmux attach-session -t <Favorite session>

Related

how to copy a tmux session entire buffer output from bash?

I am looking for a command that allow me to copy the entire output of a tmux session from bash. For example:
$ tmux ls
0: 1 windows (created Wed Mar 2 20:19:19 2022) [213x54]
I would like to copy all output in this session to a file from my bash session. Something like:
sh copy-tmux.sh [tmux-session-id]

Difference in behavior between 2 aliased cds in unix shell

I connect to a remote computer thru VNC and use Konsole for my work. Konsole is version 2.3.3 using KDE 4.3.4. I have these two aliases:
alias ll 'ls -haltr; pwd'
alias cd 'cd \!*; ll'
which I observed to have the following behavior:
When path exists, it will cd to it and also do the ll alias
When path doesn't exist, it will simply say the path doesn't exist and won't do the ll anymore
Example:
Path exists
[10] % cd foo
total 14K
-rw-r----- 1 user group 913 Jun 3 2014 readme
-rw-r----- 1 user group 1.2K Dec 3 2020 report.txt
drwxr-x--- 2 user group 4.0K Jan 12 17:50 ./
drwx------ 77 user group 8.0K Jun 24 11:57 ../
/home/user/foo
[11] %
Path doesn't exist
[10] % cd nowhere
nowhere: No such file or directory.
[11] %
Now our department has transferred to another division and we've just started to connect remotely thru Exceed TurboX. I still use Konsole but the version is now 2.10.5 using KDE 4.10.5. I copied over the same two aliases, but I'm now observing a different behavior:
When path exists, it will cd to it and also do the ll alias (basically same as #1 above)
When path doesn't exist, it will attempt to cd AND still do the ll (different as #2 above)
So for #2, here's how it looks like:
[10] % cd nowhere
nowhere: No such file or directory.
total 120K
-rw-r----- 1 user group 272 Jan 6 2021 .cshrc
-rw-r----- 1 user group 1.2K Jan 6 2021 .alias
drwxr-x--- 2 user group 4.0K Jan 12 17:50 ./
drwx------ 77 user group 8.0K Jun 24 11:57 ../
/home/user
[11] %
I would like to know how to get behavior #2 of the previous working environment to this current working environment.
I've added the information on the Konsole and KDE versions because if the behavior is due to the version and there's no workaround, then I'll just be sad for the rest of my life working in this new remote desktop env. ^_^
I'm currently exploring a "check first if the path exists before doing ll" but to no avail. :'(
Edit:
The shell I'm using is tcsh
% printenv SHELL in both environments showed /bin/tcsh
And in addition:
Old environment
% echo $version
tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec
New environment
% echo $version
3
The information in the question is still not sufficient to find out why tcsh behaves differently in the two working environments.
The alias defines a sequence of commands (cd followed by ll) without any condition.
alias cd 'cd \!*; ll'
On one system the execution of the alias seems to stop if the cd command reports an error for currently unknown reasons.
The correct way to prevent the execution of ll after a failed cd command would be the conditional execution of the ll command, e.g.
alias cd 'cd \!* && ll'
The decade long advice is: do not use aliases, use functions.
ll() { ls -haltr "$#" && pwd; }
cd() { cd "$#" && ll; }

Accidentally used -S when creating my tmux session instead of -s, where is my session?

I created a new session of tmux, intending to use the -s flag to name it, but confused the command with -S which specifies a socket. I know the session is alive, because the processes I started in it are still running. But when I try to list running sessions it does not appear. Where is my session and how do I recover it?
In tmux option -S means socket path (from man tmux):
-S socket-path
Specify a full alternative path to the server socket. If -S is specified, the default
socket directory is not used and any -L flag is ignored.
So you have to find out the parent directory where tmux was run with
-S option and pass this option to tmux to point it to the
alternative socket path. You could for example find PID of the
tmux process:
$ ps aux | grep '[t]mux'
ja 15121 0.0 0.0 20252 2236 pts/6 S+ 00:44 0:00 tmux -S new
And then check this process cwd in /proc like this:
$ ls -l /proc/15121/cwd
lrwxrwxrwx 1 ja users 0 Aug 19 00:52 /proc/15121/cwd -> /home/ja
And then to refer to this tmux session:
$ tmux -S /home/ja/new ls
0: 1 windows (created Sat Aug 19 00:44:46 2017) [212x65] (attached)

How can I reattach to my byobu/tmux session?

I'm using byobu with a tmux backend in Ubuntu 14.04. The standard methods for selecting/viewing sessions such as byobu-select-session and tmux ls do not find the session.
I created a session via incorrect syntax byobu -S wiki and later detached. (I should have done byobu new -s wiki)
The session still exists, according to
$ ps aux | grep byobu
gert 4032 0.1 0.0 29988 8912 ? Ss Jun13 1:46 tmux -f /usr/share/byobu/profiles/tmuxrc -S wiki
I can also see a reference to the session in /tmp
$ ls /tmp/tmux-1001/ -l
total 0
srwxrwx--- 1 gert gert 0 May 30 17:06 default=
srw-rw---- 1 gert gert 0 Jun 14 15:07 wiki=
Try
byobu -S wiki ls
to see if the tmux session is still there. It probably is given your ps output, and will be listed as session 1. Then try
byobu -S wiki attach-session -t 1
Maybe specify the full path to where you can see the "wiki" unix socket that was created when you did byobu -S wiki, which will be in whatever directory you executed that command in originally. Other behavior may occur if byobu or tmux was customized, but basically after you specify byobu -S <path-to-put-socket|path-to-existing-socket-including-socket-name> everything following is going to get passed to tmux. tmux just needs byobu to tell it where to look for its sockets, otherwise it will look in TMPDIR or something by default.
Hope this helps. This is my first ever stackoverflow question that (1) wasn't already answered many different ways, and (2) I knew a possible answer or at least a pointer in the right direction. :)

How to reorder TMUX sessions?

Is there any way to re-number or swap tmux sessions, just as you can renumber or swap tmux windows? I can't see any command for it and want to easily switch between certain sessions.
They're sorted by name (which defaults to a number) You can change the names so that they appear in the order that you prefer.
Outside of tmux:
tmux rename-session -t 0 zzz
inside tmux:
C-b $
Or:
c-b : rename session -t current_name new_name
The default ordering seems to have changed recently from name to index. If you want to put it back to name, try this in your .tmux.conf
bind s choose-tree -sZ -O name
If you'd like to "manually" order your sessions, you can prefix the session name with a zero-width or invisible unicode character. For example:
$ tmux rename-session -t charlie $(echo -e "\u200B")charlie
$ tmux rename-session -t beta $(echo -e "\u200C")beta
$ tmux rename-session -t alpha $(echo -e "\u200D")alpha
$ tmux list-sessions
charlie: 1 windows (created Sun Nov 2 12:39:30 2014) [284x87] (attached)
beta: 1 windows (created Sun Nov 2 12:39:27 2014) [284x87]
alpha: 1 windows (created Sun Nov 2 12:39:23 2014) [284x87]
The drawback is that you still have to refer to the session using those characters.

Resources