Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Include GNUScreen info at the PS1 #2189

Unanswered
dr-costas asked this question in Q&A
Discussion options

Hi,

How can one include GNUScreen info at the PS1? Specifically, I would like to know:

  • If I'm not in a GNUScreen, then if there are active GNUSCreen sessions, how many are those
  • If I'm in a GNUScreen session, which GNUScreen session am I in?

I have figured out how to do this in my own, not bash-it, PS1, but I want to transfer that to bash-it. Any help?

You must be logged in to vote

Replies: 2 comments

Comment options

If you don't mind sharing the snippet you have working, we can think about a place to put it.

You must be logged in to vote
0 replies
Comment options

I don't mind at all! I doubt that is good enough to put it somewhere, but I guess you can use it to get an idea.

This is what I use:

# Function: existsScreenSession
function existsScreenSession {
	screenLs=`screen -ls | head -n 1 | tr -d '[:space:]'`
	if [[ "$screenLs" == *: ]]
	then
		existsScreenFlag=0
	else
		existsScreenFlag=1
	fi
	return $existsScreenFlag
}
#
# Function insideScreenSession
function insideScreenSession {
	if [ -z "$STY" ]
	then
		insideScreen=1
	else
		insideScreen=0
	fi
	return $insideScreen
}
#
# Function: getGNUScreenInfo
function getGNUScreenInfo {
	gnuScreenInfo=""
	if existsScreenSession
	then
		if insideScreenSession
		then
			gnuScreenInfo="Inside GNUScreen session: $STY"
		else
			nbSessions=$(( $(screen -ls | wc -l | tr -d ' ') - 2 ))
			if [ $nbSessions -gt 0 ]
			then
				gnuScreenInfo="$nbSessions GNUScreen session(s) active"
			fi
		fi
	fi
	echo $gnuScreenInfo
}

and I call it as:

gnInfo='$( getGNUScreenInfo )'

Then I add the gnInfo at my PS1.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /