[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: VT2 for Xorg?



On Mon, Jul 09, 2018 at 11:52:05PM +1000, Zenaan Harkness wrote:
> On Mon, Jul 09, 2018 at 09:41:32AM -0400, Dan Ritter wrote:
> > On Mon, Jul 09, 2018 at 09:08:17AM -0400, Greg Wooledge wrote:
> > > On Sun, Jul 08, 2018 at 01:08:59PM +1000, Zenaan Harkness wrote:
> > > > With a bash fn like:
> > > >   ttyGetNum () { return $(tty | grep -oE '[0-9]+$') ; }
> > > > 
> > > > Then something like this will id your current tty:
> > > >   ttyGetNum;  export Xorg_vt=vt$?
> > > 
> > > Ewwwww!
> > > 
> > > The return status of a shell function is NOT intended to be used this way.
> > > It's analogous to the exit status of a shell command.  It's a single
> > > byte, unsigned, so you can only return 0 to 255.  It's intended to convey
> > > success or failure, not to carry an actual data payload.
> > > 
> > > I recommend that you switch to using a regular variable for this purpose.
> > > I happen to like "r".  With a regular variable, you're not restricted to
> > > integers from 0 to 255, and you retain the ability to convey succss/failure
> > > through the return code.
> > > 
> > > As an aside, you can save the call to GNU grep by simply stripping the
> > > leading "/dev/tty" from the output of tty using a shell parameter
> > > expansion:
> > > 
> > >   ttyGetNum() {
> > >     local t
> > >     t=$(tty) || return 1
> > >     [[ $t = /dev/tty+([0-9]) ]] || return 1
> > >     r=${t#/dev/tty}
> > >   }
> > > 
> > >   if ttyGetNum; then export Xorg_vt=vt"$r"; fi
> > > 
> > 
> > fgconsole returns the current virtual terminal number.
> > chvt switches to a specified virtual terminal.
> 
> Sweet!
> 
> > These are from package kbd.
> 
> Was already installed by me :)
> 
> And this will satisfy Dan's objection to a perfectly good use of
> "return" values ;D

s/Dan/Greg/ # I need sleep alert


Reply to: