You are not logged in.
I'm trying to get whatever terminal I use to open with a tmux session. The session, if already running, should just be re-attached to my previous session (that is still running in the background) when I open a terminal window in SnapWM. I got this command from somewhere on this forum and it works on my netbook but refuses to budge on the desktop.
# Use this command as the last line in .xinitrc
# Attach to an tmux session that is in-progress OR
# Start a new session within your preferred terminal replacing xfce4-terminal with - for example:
# lxterminal -e ...
qterminal -e bash -c "tmux -q has-session && exec tmux attach-session -d || exec tmux new-session -n$USER -s$USER@$HOSTNAME" &&
###What really confuses me is that this works on the netbook with a functionally identical .bashrc file. The only difference between both .bashrc's is that the netbook has Synaptic options in it and I removed references to Nvidia driver tweaks.
The full .bashrc is here:
#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)
if [ -d /etc/X11/xinit/xinitrc.d ]; then
for f in /etc/X11/xinit/xinitrc.d/*; do
[ -x "$f" ] && . "$f"
done
unset f
fi
###
xset +fp /usr/share/fonts/local/ # Prepend a custom font path to Xorg's list of known font paths
xset fp rehash
## Resets the default X cursor
xsetroot -cursor_name left_ptr &
## For a dramatic 2D graphics performance increase in pixmap-intensive applications, e.g. Firefox,
## set the InitialPixmapPlacement parameter to 2:
nvidia-settings -a InitialPixmapPlacement=2 &
## use customisations from the nvidia-generated file in your home directory
nvidia-settings --load-config-only &
## To have the touchpad disabled automatically when you begin typing
#syndaemon -t -k -i 2 -d &
###
## Used to enable anti-aliased fonts primarily for LibreOffice. See .bashrc for the "xrdb -merge ~/.Xresources &" counter-part to this code
Xft.lcdfilter: lcddefault
# Start SnapWM with startx
exec snapwm
sh ~/scripts/wallpaper.sh &
## Force LibreOffice Writer to use a gtk/gtk3/kde4/generic UI uncomment one of these:
#SAL_USE_VCLPLUGIN=gtk lowriter
#SAL_USE_VCLPLUGIN=gtk3 lowriter
#SAL_USE_VCLPLUGIN=gen lowriter
SAL_USE_VCLPLUGIN=kde4 lowriter
# Use this command as the last line in .xinitrc
# Attach to an tmux session that is in-progress OR
# Start a new session within your preferred terminal replacing xfce4-terminal with - for example:
# lxterminal -e ...
qterminal -e bash -c "tmux -q has-session && exec tmux attach-session -d || exec tmux new-session -n$USER -s$USER@$HOSTNAME" &&
###Equally frustrating is my wallpaper script won't start-up either. That will have to wait for another post though.
TIA ![]()
edit: changed subject line to .xinitrc instead of the incorrect .bashrc.
Last edited by MoonSwan (2014-07-08 23:41:48)
Offline
That is your .xinitrc file, not your .bashrc file.
Nothing after the exec call gets read from .xinitrc.
Offline
Gah! Wow go me.
*sigh* I feel like an idiot. Thanks JasonWRyan.
Offline
No problem; there are a number of one liners for .bashrc that will start any interactive shell in a new or pre-existing tmux session. A quick search on guthub should throw up what you need.
Offline
No problem; there are a number of one liners for .bashrc that will start any interactive shell in a new or pre-existing tmux session. A quick search on guthub should throw up what you need.
OK so these one-liners will work for terminals within X?
I think I have a multi-liner that does work on the command line. It will start a new tmux session, or attach to one already started, when I log in at the console. I don't use this because then I forget it's a tmux session and then do a "startx" from within the tmux session which, as far as I know, is a bad idea.
# ~/.bashrc
###
# TMUX
# Put this this snippet BEFORE the aliases in .bashrc.
# This code starts TMUX with only one session (unless you start some manually), on login;
# it will try to attach to a currently running session.
# If there isn't a currently running session then TMUX will create one.
# if which tmux 2>&1 >/dev/null; then
# if not inside a tmux session, and if no session is started start a new session
# test -z "$TMUX" && (tmux attach || tmux new-session)
# fi
###[edit[ Really all I want is a way to start a terminal while logged in to X and that terminal will spawn a new tmux or attach to a currently-running tmux session. That one-liner I have in .xinitrc doesn't seem to want to work for me. Hm, github, never been there but I guess there's always a first time.
Last edited by MoonSwan (2014-07-08 00:18:11)
Offline
I'm not clear what you are after: a) to login to a tmux session when you start X, or b) when you are in X and open a terminal, it is a new or exisiting tmux session?
Or, on reflection, c) when you login, open a tmux session in the current TTY?
Offline
I'm definitely after option "b" but option "c" actually sounds better in a way. I'm sorry for the lack of clarity.
[edit] Whatever I end up using I really would like to understand the code being used too. I try hard to understand bash scripts but, in all honesty, I find such coding difficult to grasp. If I could understand why the line I'm using now doesn't work I'd feel better and less like a pain asking for help on what is, to most people on the forum I'm sure, a trivial issue.
Last edited by MoonSwan (2014-07-08 00:47:44)
Offline
b) and c) are the sane choices.
b) is the code you pasted above in #5
c) is sometihg like this in your .profile:
if [[ $(tty) = /dev/tty2 ]]; then
[[ -z "$TMUX" ]] && (tmux attach || tmux new-session)
fiie., if you login on TTY2, then start a new tmux session or log into the exisiting one.
Offline
Thank you for the help.
I did try your code out here but it didn't seem to work. I logged out completely, after shutting down X, then logged in again on TTY2 but Tmux was not running when I got to a console. After that I issued the "startx" command. Once in X I opened up a terminal window but it did not have a tmux session. What am I doing wrong?
The option b) may be the simpler answer here but I still don't know how to make it work either.
[edit] I think I figured out why your "c" option failed. When I ran htop it showed that I had multiple tmux sessions already going on! (I need to figure out how to actually stop a tmux session next ...) After I killed all the sessions through htop I logged out again completely. When I re-logged in with your code in-place tmux did start-up!I'm going to try to see if that was the issue for my original code and kill tmux sessions completely then try to login to X and open a terminal to see if tmux spawns a session.
[edit two] I did try my original code (option a, if you will) and I still can't get it to work. The only script that seems to work so far is this from my .bashrc file
# If there isn't a currently running session then TMUX will create one.
if which tmux 2>&1 >/dev/null; then
# if not inside a tmux session, and if no session is started start a new session
test -z "$TMUX" && (tmux attach || tmux new-session)
fi
##It does log me into a tmux session on the console and from there I have to detach from tmux then run "startx" to get into SnapWM. I'll have to see if I can get your code to work for me. I'm sure that this is an issue with something I'm (not) doing.
Last edited by MoonSwan (2014-07-08 02:11:17)
Offline
A quick search on guthub should throw up what you need.
I tried visiting guthub.com, but the rascals have already bought the domain ![]()
Offline
jasonwryan wrote:A quick search on guthub should throw up what you need.
I tried visiting guthub.com, but the rascals have already bought the domain
Lol. They got bought out...
Offline
Very cute and funny, thanks to both of you.
I'm going to mark this as solved because other solutions seem overly complicated and my initial tmux code does give me a session when I login to the console. It's not a big deal to then detach the session, run startx and re-attach to my session.
Last edited by MoonSwan (2014-07-08 23:40:55)
Offline
Small update:
I finally found a command to do exactly what I want to happen when I log into X. This bit of code starts a terminal and then executes tmux within that TTY after I log in to X.
[s] # Start Tmux on log-in to X (snapwm)
exec snapwm & sleep 1 && exec qterminal -e bash -c "tmux -q has-session && exec tmux attach-session -d || exec tmux new-session -n $USER -s $USER@$HOSTNAME" &&[/s]If someone would like to make that command simpler please post it and you shall have my thanks. ![]()
Edit Two: The code above starts tmux on TTY 2 on start-up but if you close the window X gets closed as well. I managed to cobble together another line of code that doesn't kill X if you close your term window. I put this into my .xinitrc and it starts up a terminal window with a tmux session going on as soon as X loads.
# ~/.xinitrc
# TMUX
# Put this this snippet BEFORE the aliases in .bashrc.
# This code starts TMUX with only one session (unless you start some manually), on login;
# it will try to attach to a currently running session.
# If there isn't a currently running session then TMUX will create one.
if which tmux 2>&1 >/dev/null; then
## if not inside a tmux session, and if no session is started start a new session
test -z "$TMUX" && (exec qterminal -e bash -c "tmux -q has-session && exec tmux attach-session -d || exec tmux new-session -n $USER -s $USER") &
fiLast edited by MoonSwan (2014-07-23 19:39:00)
Offline