I like to keep my shell sessions named with useful titles as I work, this helps me keep track of what I'm using each of the many tabs for.
Currently to rename a session I double click its name on the tabbed part of the console - is there any command that I can use to do this from within the shell? It would save me a bit of time.
thanks in advance
edit :-
I am using KDE's Konsole shell.
The article How to change the title of an xterm should help.
Currently to rename a session I double click its name on the tabbed part of the console
This sounds like you're using KDE's Konsole. Is this true?
If so, in KDE 3:
dcop $KONSOLE_DCOP_SESSION renameSession "I am renamed!"
In KDE 4, the old DCOP interfaces haven't been ported over to the new D-BUS IPC yet, but you can change the settings for tabnames to follow the window name set by each screen, and set the window name as described by the other answers.
According to this page, you should be able to use something like this:
echo -n "\033]0;New Window Title\007"
I'm not in Linux at the moment, so this is untested. I do know that it is possible to change the window title under program control, so this seems likely to work.
For /usr/bin/konsole
you can change the title of a konsole terminal from the menu:
Settings->Edit Current Profile->Tabs
edit "Tab title format" to be whatever you want. After interacting with the shell, the title will reset to what you put.
for /usr/bin/xterm running in xorg-server 2:1.10.1-1ubuntu1
echo -ne "\033]0;My Fun X-Terminal\007"
The answer to this really depends on the terminal program you're using.
However, I'll just assume it's sensible, and emulates an xterm enough that it respects xterm escape codes - in which case, you probably want to look here : http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#s3
Note: unwind's example below requires echo to be called like this "echo -ne", otherwise the '\' characters are echoed literally.
For the default terminal on Ubuntu (I'm still on 10.04) try xtitle.
$> sudo apt-get install xtitle
...
$> xtitle --title wow it worked!
or simply
$> xtitle this is great
Related
I'd like to script opening a workspace with the 'next' available number and then have open in that workspace maybe a two windows each already pointed at a specific view. Any pointers on how to do that? Is i3 actually scriptable in this regard? I have only just started using i3 and loving it, just want to now have it do things I need on a regular basis ;-)
All of i3's "scripting" that isn't already in the config is done through i3-msg
i3-msg sends messages to i3 window manager. It's mostly config lines(or IPC, which is a bit harder).
How can I open a work space from the command line in i3
How do you open it in your config?
bindsym Mod4+1 workspace $ws1
Something like that right? Now, using i3-msg to move to workspace 1:
i3-msg workspace 1
Simple, right?
The rest of your question is pretty unclear, but I'll do my best:
I'd like to script opening a workspace with the "next" available number"
How you'll start out with doing that is(after doing man i3-msg):
i3-msg -t get_workspaces
This returns a json(if you've done any coding you'll feel warm inside and if not you're going to be scared by the output). Then I'm going to ask you to read up on this:
https://i3wm.org/docs/ipc.html#_receiving_replies_from_i3
Using jq or something like json.sh to parse through the output with bash, you should get which workspaces are "active", example:
[{"num":3,"name":"3","visible":true,"focused":false,"rect":{"x":0,"y":0,"width":1920,"height":1080},"output":"HDMI-1","urgent":false},{"num":2,"name":"2","visible":true,"focused":false,"rect":{"x":3520,"y":0,"width":1920,"height":1080},"output":"VGA-1","urgent":false},{"num":1,"name":"1","visible":true,"focused":true,"rect":{"x":1920,"y":32,"width":1600,"height":868},"output":"eDP-1","urgent":false},{"num":5,"name":"5","visible":false,"focused":false,"rect":{"x":1920,"y":32,"width":1600,"height":868},"output":"eDP-1","urgent":false}]
Reading through the website I gave you, you can see, workspaces 1,2,3 and 5 are "active" aka have windows in them. After parsing the actual json you'll end up with an array or something of this. If you want to spawn on 4(the real "next" desktop) or 6 (aka biggest number + 1) is up to you. You didn't mention what you want to script it in, so I'll leave that to you to figure out.
maybe two windows each already pointed at a specific view
I'm not sure what you mean. You probably want 2 windows of X(we'll use a terminal in this case) in the workspace we've determined as "next" ?
Let's go back to i3-msg for a bit.
Imagine you doing whatever you're trying to do, manually, as a list of commands you're firing to i3.
"Go to workspace X" : i3-msg workspace 4
"Spawn a program called kitty there": kitty
"Split vertically and spawn another program": i3-msg split v
"Spawn another kitty window": kitty
After that you can get back to your current workspace(I suggest saving it in a variable and just reusing i3-msg workspace $curr_workspace).
As I said, the question wasn't about the actual scripting so I left that out to figure it out on your own, but don't hesitate to ask a concrete question under the bash tag. :). Hopefully I didn't completely misunderstand your question.
Welcome to the i3 community.
#Nephilim's post is excellent. Just to add a trick to the toolbox...
Sometimes you might want to script some action relative to a particular window. Like:
Give me a test environment next to this browser.
You can get the window ID by running xwininfo and clicking the window that you want to anchor your automation to. The window ID can be used as a parameter to i3-msg.
For example, running the command below will let you select a window and then will set that window's width to 1000:
i3-msg "[id=$(
xwininfo \
| sed -n 's/.*Window id: \(0x[0-9a-f]*\).*/\1/p'
)] resize set 1000"
I have been using YADR Yet Another Dotfile Repository to enable a whole bunch of features in vim.
Given that I split my terminal window, I'd like to reclaim some of the screen estate by shortening the command prompt.
Does anyone know how to edit the zsh files to accomodate this, specifically pertaining to a .yadr setup?
Thanks internet
You can just set PROMPT (and/or PROMPT2, PROMPT3 and PROMPT4) in a file with the extension .zsh in the directory ~/.zsh.after/, for example ~/.zsh.after/myprompt.zsh:
PROMPT1='myprompt %# '
PROMPT2='> '
Have a look at the sections EXPANSION OF PROMPT SEQUENCES and following in zshmisc(1) for some details on zsh prompts.
Also, have a look at the YADR documentation on themes for more details on how to use premade themes.
If you want to just shorten your computer name instead of changing the whole prompt you can issue the command:
scutil --set HostName "here"
I'm new to linux. And I'm confused with the different shell titles in linux.
for example, when I called "/bin/sh", I saw
sh-3.1#
but when I used "su root", I saw
my-environment:~#
and when I logged in as normal user, I saw
user#my-environment:$
I kind of notice # means root and $ means non-root, but could some explain how I got the above titles?
Thanks a lot!
The text at the shell prompt is controlled by the variable $PS1 (and sometimes $PS2 $PS3 $PS4). This blogpost explains how you can customize the prompt in many ways.
Do echo $PS1 in the different terminals to see the current value.
This depends on your variable environment $PS1.
To see what I mean, try doing PS1=something, and see what happens.
To reset it you could do source ~/.bashrc.
So, why do you have different prompt according? Because you don't load the same files according to the command you type to open your sessions, so you end up with different configs, hence a different $PS1
After I make changes in .bash_rc or .bash_profile, when I start GNU screen, it doesn't recognize those changes.
I can
source ~/.bash_profile
and it works for the current screen window I have open, but I have to do that for every screen window I have open.
How do I get screen to read my latest changes in my bash configuration?
If you want screen to always treat your shell as a login shell, and source the same files that would be read if just started a new shell normally, add the following to ~/.screenrc (or maybe ~/.byobu/.screenrc, as pointed out in the comment):
shell -$SHELL
This way, you don't need to manually tell it to source your files each time you start a new screen. Though you would have to if you just made changes and wanted those changes to be reflected in your current screen.
The documentation for this (and lots of other screen details) can be found here. Basically, shell is a command to screen telling it to run the following when it needs to create a new shell. $SHELL is the usual variable holding the path to your preferred shell. And the dash - in front of $SHELL indicates that it should be run as a login shell (which will typically mean it sources your ~/.bash_profile, etc.).
It's worth pointing out, however, that screen defaults to just inheriting most environment variables from the shell where you start screen; and a login sub-shell may alter some environment variables in unexpected ways. I ran into a situation where elements of my $PATH were basically permuted. I solved the problem thanks to this particularly excellent answer on superuser.
You may notice the source command available. It's important to note that this sources a file of screen commands, rather than shell commands. Other relevant (screen) commands include eval and exec.
You have to do it in each screen that you have open since they are all different shells. If you need the change every time a new shell is opened, I suggest you put the changes in ~/.bashrc instead.
Apparently, you can send a command to all windows at once using this syntax:
C-a :
at "#" stuff "source ~/.bash_profile^M"
Is it possible instead of loading /bin/bash, for my terminal to load emacs or emacsclient when I open it up, with a session for eshell? And is it feasible to ssh->screen from an emacs session without running into problems?
I want to do this purely to learn about emacs being as I like it so much.
No hate text, etc please :)
emacs -f eshell
EDIT:
If you don't want to start a new emacs you can use emacsclient.
emacsclient -e '(eshell)'
Make sure you have started the server the best way to do it is to add
(server-start) in your . emacs
You can set your shell to /usr/bin/emacs (or wherever it is) to make it your default shell. It will probably act weird though since Emacs is not a shell. It's an editor. Programs expect your shell to behave in a certain fashion and Emacs won't work that way.
You can do an M-xtermret to get a terminal from which you can connect to a remote machine and start a screen. I don't know about the quality of the emulation though. No harm trying.
Neither of these look useful to me and the former is definitely a trouble maker.
Yes you can. I did for a few months once. A few things act funny most can be tamed. It was a great laugh to see coworkers react when they saw me log in to emacs.
Just tried running screen from within Emacs (in a shell buffer), but I get the following:
angelv#vaso:~$ screen -D -R
Clear screen capability required.
angelv#vaso:~$
so I guess that's not possible. In any case, I don't see why you'd want this (and I use daily screen + emacs).
echo /usr/bin/emacs >> /etc/shells
chsh -s /usr/bin/emacs