You are not logged in.
Hello All, my first post here, I am new to CrunchBang but not Linux. My $HOME/.bashrc starts with following line:
source ~/profile/dotfiles/.bashrc_screenThis file contains following code (comments and echos were added for debug purposes):
function scrr_attch_sess_tab_open() { screen -S "$attached_session" -X chdir "$@"; screen -X screen; }
function scrr_reattch_or_start_new() { (screen -rd "$attached_session" || screen -S "$new_session_name_err") && exit; }
if [ "$TERM" == "xterm" ]; then
new_session_name_ok="ok_mode";
new_session_name_err="err_mode";
attached_session=$(screen -ls | grep 'Attached' | awk '{print $1}' | head -1);
detached_session=$(screen -ls | grep 'Detached' | awk '{print $1}' | head -1);
echo "A: $attached_session" >> /tmp/screen
echo "D: $detached_session" >> /tmp/screen
if [ "$attached_session" != "" ]; then
echo "`date`: attached_session: $attached_session" >> /tmp/screen
#scrr_attch_sess_tab_open "$(pwd)";
#scrr_reattch_or_start_new;
elif [[ "$detached_session" != "" ]]; then
echo "`date`: detached_session: $detached_session" >> /tmp/screen
#screen -r "$detached_session";
#scrr_attch_sess_tab_open "$(pwd)";
#scrr_reattch_or_start_new;
else
echo "`date`: else branch" >> /tmp/screen
#screen -S "$new_session_name_ok" && exit;
fi
fiI have investigated that following two variables are always empty (no mather if I have detached/attached/existing/nonexisting screen session) and this causes that script always falls into elese branch:
$attached_session
$detached_sessionI have tried to verify if my code is OK by creating the following "copy" of script and calling it. The result is that the code should be correct because when I issue this script from command line it works as expected:
#!/bin/bash
if [ "$TERM" == "xterm" ]; then
new_session_name_ok="ok_mode";
new_session_name_err="err_mode";
attached_session=$(screen -ls | grep 'Attached' | awk '{print $1}' | head -1);
detached_session=$(screen -ls | grep 'Detached' | awk '{print $1}' | head -1);
echo "A: $attached_session"
echo "D: $detached_session"
if [ "$attached_session" != "" ]; then
echo "1"
elif [[ "$detached_session" != "" ]]; then
echo "2"
else
echo "3"
fi
fiWhat is interesting is examination that, when I comment the lines which are appending to /tmp/screen (in first code) it also magically supress those two lines:
echo "A: $attached_session" >> /tmp/screen
echo "D: $detached_session" >> /tmp/screenThis is something that I cannot understand. Before CrunchBang I had Fedora and this script worked. The whole purpose of script is to have opened always only one instance of terminator and only one instance of screen but with "tab" inside screen which is open in aporoporiate path. On Fedora this worked that way, when i issued terminal from DoubleCmd it opened me new "tab" in screen which pointed to path from which I issued the terminal. Thank you for any idea.
Last edited by wakatana (2014-02-25 00:40:07)
Offline
Finally I got it. There was problem with broken pipe which seems to be solved by nawk and variable named session. I've also little bit update the script. Here it is, hope somebody will find it usefull
feel free to comment
############################################################################################################################################################
# OSATEAT 1.0 - One Screen And Terminal Emulator At Time
#
# Description:
# This script opens new screen's "tab" according actual DoubleCmd's panels paths (or according actual path from which terminal emulator is issued).
# if screen was not running - start it,
# if screen was detached - attach to it,
# if screen was attached in another window - detach/reatach to it.
#
# Summary:
# There will be always runing only one terminal emulator and only one instance of screen at given time.
# The only thing that will change are tabs in screen.
# Tthere will be always one terminal emulator icon on tint2
#
# TODO:
# - In dualhead (multi monitor) perserve the display where terminal emulator was open from
# - Fix accent directories problem
#
# Known Bugs:
# - Does not works with directories which contains accent
############################################################################################################################################################
if [ "$TERM" == "xterm" ]; then
new_session_name_ok="ok_mode";
new_session_name_err="err_mode"; # Hopefully this will be never used
sessions=$(screen -ls 2>&1)
attached_session=$(echo "$sessions" | grep 'Attached' | nawk '{print $1}' | head -1);
detached_session=$(echo "$sessions" | grep 'Detached' | nawk '{print $1}' | head -1);
if [ "$attached_session" != "" ]; then
# 2.1 Open new tab according to $(pwd) variable
screen -S "$attached_session" -X chdir "$(pwd)" && screen -X screen;
sleep 1;
# 2.2 Reatach to attached terminal. Old terminal emulator window exits and new terminal emulator window is created,
# Again, if this newly created screen session will be detached/killed (ctrl+a+d or ctrl+a+k or ctrl+d) terminal also exits
# Hopefully this will be never used: screen -S "$new_session_name_err"
(screen -rd "$attached_session" || screen -S "$new_session_name_err") && exit;
elif [ "$detached_session" != "" ]; then
# 3 Wait in background for 2 seconds until screen is connected to detached session and then use same commands as in 2.1
sleep 2 && (screen -S "$detached_session" -X chdir "$(pwd)" && screen -X screen;) &
screen -rd "$detached_session" && exit;
else
# 1. Start new screen session (when session will be detached or killed the terminal from which it was invoked also exits)
screen -S "$new_session_name_ok" && exit;
fi
fiOffline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.