How do you duplicate a shell instance in Unix? - macos

My specific problem is the following: I am using Mac OS X with the Visor app for terminal. This lets me do cool pop-in/out stuff with terminal for quick access. The problem is, I lose the ability to move the window around and re-size it, something that becomes important when I start opening up multiple buffers in emacs and want to view some at the same time in a window larger than 80 wide.
Does anyone know how to duplicate a shell window/instance, so that a new window appears with the same history, current working dir, aliases, etc...? Even more specifically, can this be done in Mac OS X such that the new window is in a different "style", (basic, pro, sands, etc..).

I'm not familiar with Visor, but simply using a terminal emulator such as screen might give you what you need. From a terminal, invoke 'screen'. That will give you a shell prompt. From another terminal, invoke 'screen -x'. Now each terminal will be attached to the same shell, with the same history, etc. See screen(1) for details.

Related

Is there a way to determine if a terminal is focused without asking the window manager?

I want to change some tmux styling when the terminal loses focus/becomes inactive (i.e. when I've clicked on an open Google Chrome window). I know I could check with the window manager to see which application window is focused, but this doesn't work across window managers.
Do terminal emulators themselves expose this information at all?
I tried running showkey -a to see if any escape sequence was sent when focus was lost, and it doesn't look like it.
I think some terminals implement this, but not all, based on this comment on the issue tracker for the vim-tmux-focus-events plugin:
About the question "I was expecting the event to fire when changing focus between different windows in my window manager": yea, I see how that would be very useful. I think this might be dependent on the terminal application you're using. I just tested this on OSX and here's some quick results:
it's working for iTerm when tmux is running inside the window
not working for iTerm running plain bash + vim inside (no tmux)
not working for Terminal.app (with or without tmux)
[...]
So, if I'm not wrong, it's up to terminal applications to implement "focus gained", "focus lost" functionality.
I have a vague memory (though I don't remember for sure) that focus gain/loss might have worked for me when using that plugin and gnome-terminal, so it might be worth a try.

Manipulate OS X windows with script

Ok, so I'm trying to make my setup super simple by creating a script that I can run in the morning that will launch all the applications that I use in the day and lay them out across my 'spaces' how I like them.
This was going ok and I was easily able to have a bash script launch the apps and then call to an AppleScript to move and resize their windows.
However, I like to use the new El Capitan feature and have some of my spaces as 'split view' spaces. E.g. Full screen Xcode/Terminal split. I can't seem to find a way to control this via a script.
Tl;dr Does anyone know how to get a bash script/AppleScript to put two applications into 'split view' on OS X El Capitan?
Looks like that first bit about launching and full-screening apps can be done with a fairly simple script, though it requires enabling Accessibility permissions first. It, however, won't do the split-screen bit.
I kept looking though and Better Touch Tool (pay what you want, $4.49 minimum) seems to get the closest of anything I could find, allowing you to trigger Full Screen mode and bring up the split screen Expose selector in the same action. It seems to be doing this by emulating a long mouse down on the full screen window control button (the green one in the top left). What you get is this:
I've been playing around with this and it seems there might be a (so far seemingly very un-intgelligeble, though reliable) way to control the order of full screen apps and trigger an app into split screen mode in a situation where that previously full-screened app is the only option available for splitting the screen.
For example, given the following, accomplished by launching iA Writer into full screen (space 2) via ⌘+^+F:
Focusing Safari and using Better Touch Tool to trigger split screen mode results in:
... Only one split screen app, even though there's several apps still running.
From this position you could use the "move to position" action in BTT and trigger a click on the only available app— I would think this could theoretically accomplish what you want, although it's convoluted and a bit suspect.
All that being said, it seems like the only way to get two apps launched into split screen mode without touching the mouse, since this could all be a BTT workflow you trigger from an Automator script. Digging further, you might be able to learn how BTT accomplishes their actions and write a program that does this for you, but we're already way beyond bash or simple cli scripting.
I personally just use Spectacle and tmux to zoom my windows around, though I admit, automated split screen would be somewhere close to live changing.

The way how run program from shell script and specify its positon on screen

is in shell (Mac OS X Lion) a way how run program on specify position on screen?
I want to run two programs and specify their position on screen so one window will be next to another and they will be centered on screen.
You could try to hack something together using AppleScript. This link shows you how to set the window geometry of a certain application. The problem might be in actually talking to the processes that you just started. This SO question deals a bit with using the process id to talk to an app using AppleScript.

Remembering terminal states in OS X (like Fluid for the shell...)

I have a few different things open in the terminal whenever I'm developing -- log tailing, Ruby console, plain shell in a certain directory, and so on.
How do I:
start all those things at once, hopefully in the right position on the screen?
make them distinct so I can switch to them with Quicksilver / Alt-Tab?
Fluid solved this problem with all of my web apps, so now I want to do it with my terminals.
And while we're on the topic, has anyone found a working solution for getting OS X to remember window positions on an external monitor? If I unplug it and plug it back in, I have to drag everything back to the same position (although at least Mercury Mover makes it possible to do it with the keyboard.)
Open Terminal, and go into Preferences, then go into the settings tab, and create a new setting for each of your windows that you want. Either give them all different colour schemes, or duplicate a colour scheme multiple times for them all to have the same settings. Under the shell sub-tab, add "Run command" to be run at shell startup. (This is the command that will cd to the directory you want, or tail a log).
Then initialise the windows as you want. Then click Window in the main menu and select Save Windows as Group...
In OSX Yosemite you can use (in Terminal) Window -> Save group. It will do all the work for you.

Unable to use X clipboard in Screen

I read the following code in Unix Power Tools on page 117
*VT100.Translations: #override\
Button1 <Btn3Down>: select-end(primary,CUT_BUFFER0,CLIPBOARD)\n\
!Shift <Btn2Up>: insert-selection(CLIPBOARD)\n\
~Shift ~Ctrl ~Meta <Btn2Up>: insert-selection(primary,CUT_BUFFER0)
I have not managed to see any effect of the above code.
How can you use X clipboard in Screen, without your mouse?
Using the mouse. Left-click drag to select and usually the middle mouse button pastes but some terminals may differ (PuTTY uses right-click). If you only have two buttons you click them both together (left mouse button + right mouse button).
In reply to comment below ("Can you do it without your mouse?"):
ctrl-insert : copy
shift-insert : paste
shift-delete : cut
shift-ctrl-C : copy
shift-ctrl-V : paste
Not all applications will support the last three (though Konsole does). In fact most console applications will not allow you to delete text once it's printed.
As far as selecting text without a mouse I'm not sure there's a generic mechanism for that. It's probably terminal and/or application specific (ie, vim has it's own keys for marking and copying text - but only within vim). You could do it with mouse emulation but I'm sure that would be a painful process.
You can't use the traditional Mac/Windows shortcuts in a terminal because they were reserved for different actions long before these OS existed (ie, Ctrl-C terminates the running process).
I'm trying to use Ctrl-C in X
X does not handle these operations directly, they are handled by the application. That's why modern GUI programs like Firefox or Gedit support Ctrl-C for copy but terminals and command-line programs generally do not. As I said, it's a conflict in established conventions and Ctrl-C for kill got in first.
BTW, you could do some key-remapping if it drives you nuts but then you would be learning bad habits when you use a different machine. Best to just get used to it or do most of your editing in a GUI application.
More Information
EDIT: For a Mac, this may help: MacOSX-to-Konsole or This or This. It looks like you need to replace Ctrl with Command on Mac keyboards. It seems like Terminal the mac console has a right-click context menu for copy-paste so to do it the traditional way you me need to install a different console program or change some settings in Terminal.

Resources