From within the command line, how can I detect if the terminal running the command is associated with the gnome-terminal tab that has focus?
Ultimately, I am trying to make the terminal play a sound when any long running command finishes, except those that I'm actively interacting with.
I have a my terminal configured using trap "..." debug and $COMMAND_PROMPT such that it plays a sound when any long running command finishes, but that includes commands that take user input like man. I figured an elegant solution to the interactive process problem would be to only play the sound if the tab does not have focus, but I'm struggling to find a way to do so.
Related
I am trying to run x11 on cygwin, mainly to run xfig utility, and I am facing a problem.
When I run xinit to start x11, I get a big popup window with one terminal open. But I am unable to open any other terminals in it. To be more specific, when I run "xterm &" in it, a new terminal opens up but it sits on top of the old terminal, and there is no way I can move this window, so the old terminal is as good as useless to me, till I kill the new terminal.
I also tried running "xwin". There a big window popped up, but it does not contain any terminal, and I cant open any terminal, whether by left or right clicking.
I also tried running "startx". A big window opens up but gets killed automatically after a few seconds.
How can I use x11 effectively on cygwin? As of now, I can use with "xinit", but with only one terminal.
The proper mode to start the Xserver on cygwin is to use starxwin.
From its manual:
The startxwin script is a front end to xinit(1) that provides a
some what nicer user interface for running a single session of the X Window
System in multiwindow mode. It is often run with no arguments.
To move windows around, you need to have a window manager running. You can start this either from the xterm, by passing the name of the window manager as an argument to startx, or by starting it from your X11 startup configuration (memory says that would be ".xinitrc" in your home directory on most unix boxes, but I am not sure if that's true on Windows using Cygwin). The .xinitrc file is "just" a shell-script, with the end of the script indicating "X should shut the server down now" (see example at the end).
There are many possible window managers, including fvwm2 (which according to your comment, you managed to find on your own). A full list of X11 window managers is probably too long to fit in this answer (there are many, there are new ones popping up, and old ones going out of maintenance on an ongoing basis). Some of the not entirely uncommon ones are fvwm2 (already mentioned), cinnamon, twm, ctwm, ratpoison, ... For a more up-to-date list, ask your favourite search engine for "list of X11 window managers".
Example .xinitrc file:
# This is an example .xinitrc file, starting first an xterm,
# then a window manager. As the X server terminates when this script
# does, we start the X terminal in the background, but the window
# manager in the foreground, so that "WM exists" signals "X server shuts down"
xterm &
fvwm2
When working in GUI we do alt-tab (or cmd-tab in mac) to switch between multiple programs, for example I am writing a text file in a text editor and then I do alt-tab to switch to already running browser to google up something then I alt-tab again to come back to keep editing.
How do you perform such "switch between" programs in command line interface - for example working with a ssh command line shell?
EDIT: I forgot to mention it, I am using ssh to connect to my university's server, and they don't have screen & tmux installed, and my account have no right to install any new apps... Is there any built-in functionality to perform this task, or any work around? For exmaple can I "minimize" running proggram and come back to regular shell interface, do some work, then display the "minimized" process again?
Another workaround: use the shell's job control, eg if you're editing a file, CTRL-z pauses the editor and brings you back to the shell, where you can compile, see manpages, browse the web or whatever -- and of course you can background the browser or anything else.
Screen command offers the ability to detach a long running process (or program, or shell-script) from a session and then attach it back at a later time.
As a crude workaround, run multiple terminal windows on your computer, and alt-tab between them.
Incidentally, at the Linux console, you can switch virtual terminals with ctrl+alt+F for at least F1 through F6, commonly F8 or more (depends on how the distro sets them up). Not your case, I know, but in case future visitors should benefit.
If you are comfortable in Emacs, it allows you to run multiple independent ansi-term buffers.
You can also use "GNU screen" to emulate multiple terminals in one terminal.
I have a seemingly simple problem that I can't figure out how to solve.
I have a bash script which launches a program in the background within a loop. However, each time the program opens up it launches a window and focuses on it. Is there a way to launch a process and have all of the windows which it launches be minimized or completely suppressed?
Here is my code:
#!/bin/bash
while true; do
process1 & P=$!; #I need to hide all of the windows in this process
process2;
kill $P;
wait;
sleep 0.1; done
Thank you for your help.
Use xdotool, replace name_in_titlebar with the name from your titlebar :D
xdotool search --name name_in_titlebar windowactivate
xdotool key ctrl+super+Up
This is up to the Window Manager. Try looking up how to prevent focus stealing in your wm documentation.
For a more general approach, you can start a second X server (startx -- :1 and then Ctrl-Alt-F8 to switch to it), run an instance of Xnest to get an X-server-in-a-window where subwindows won't steal focus, or run a vncserver/nxserver that the windows can spam and you can occasionally connect to and look at if you want. With any of these set up on e.g. display :1, you can redirect your process's window with DISPLAY=:1 process1.
I have a gVIM script that parses current buffer and offers user to select one of multiple choices. It is implemented as console input, but since i'm using graphical version of gVIM, maybe it's possible to use graphical version of multiple choice dialog? I have tried to use python + Tkinter but it's very unstable and is not working on some NIX boxes :(. Any ideas?
GVim has, in its functions and settings, nothing that would enable showing GUI elements (with a few noble exceptions, like closing dialog and such.).
That being said, GVim is open source, and nothing stops you from downloading the source and messing with it.
After some research i have found a solution. VIM supports so-called "clientserver" mode and external application can send a command to it. So this task (and many others) can be solved with following technique (tested on Windows, OSX and Ubuntu):
VIMscript that handles a command launches standalone GUI script in
separate process and returns.
Standalone GUI script (python/ruby/.exe/whatever) displays GUI and
waits for user interaction.
After user interaction, standalone GUI script closes it's window,
communicates back to VIM via "clientserver" interface (call another
script, open file, move cursor etc) and exits.
I would really like to find a way to start gvim without the terminal losing focus.
I found a way to use gvim to display code when debugging in dbx.
Gvim as dbx frontend
This works great but it causes gvim to steal the focus every time it hits a breakpoint or changes line.
I am pretty sure I could adapt a terminal keeping focus to work inside dbx.
I am running solaris on a sparc processor.
How can I start gvim without it taking focus from the terminal that started it?
If you're a KDE user, you can start gvim with the kstart command. The kstart program has extensive options for controlling the behavior of the program you're starting. The --onbottom option might accomplish what you're trying to do.