How to change terminal prompt in zsh using YADR - vim

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"

Related

How can I enter text into Launchy and append it to the end of a text file?

I'm a Debian Stretch user coming from Windows. In Windows with the launchy app (also available for Linux), I had a method of entering text into launchy that was then appended to the end of a .txt or .md file.
To do this in Windows, I created a file called note.bat that contained the following:
echo %*>>"C:\collectednotes.md"
I'd make launchy aware of note.bat by adding its containing folder to “Launchy” → “Settings” → “Catalog” and adding filetype *.bat.
From there, I'd launch launchy, type note, hit Tab, enter some text, hit Enter, and then the text would be added to the end of collectednotes.md.
A mostly working process is detailed in my answer below. I'll give the green checkmark answer to anyone that can adjust this process (via note.sh and/or launchy plugin setup detailed below) to appropriately handle all special characters.
This may contain the solution to this question:
Which characters need to be escaped in Bash? How do we know it?
Solved (almost). I'm keeping this question unanswered and will give to whoever completes the remaining ~5%. Steps to get the 95% solution with xfce4-terminal version 0.8.3-1:
Install launchy and launchy-plugins (both are version 2.5-4 for me):
apt-get install launchy
apt-get install launchy-plugins
Open terminal to default location of ~/ and create collectednotes.md:
echo "# Launchy Notes Collected Here" > collectednotes.md
Create note.sh shell script:
echo '#!/bin/sh' > note.sh
Create shell script line 2:
echo ALL_ARGUMENTS='"$#"' >> note.sh
Create shell script line 3:
echo 'echo "$ALL_ARGUMENTS" >> ~/collectednotes.md' >> note.sh
If you open note.sh, it will look like:
#!/bin/sh
ALL_ARGUMENTS="$#"
echo "$ALL_ARGUMENTS" >> ~/collectednotes.md
Make note.sh executable:
chmod +x note.sh
Launch launchy and click the gear icon in upper right for settings. If consistency with launchy for Windows is desired, set launchy Hotkey to Alt+Space. If you receive a keyboard shortcut conflict message as I do on Debian with Xfce, first go to Settings, Window Manager, Keyboard tab, and clear Alt+Space as the shortcut for Window operations menu.
Next in launchy settings, go to Plugins tab and enable the plugin Runner. Click the + button and create a new Runner custom command as follows:
- Name: note
- Program: /home/YOURUSERNAMEHERE/note.sh (launchy does not like Program path of ~/note.sh, so a specific path with username is required)
- Arguments: '$$'
Click the Catalog tab and hit Rescan Catalog just in case. Hit OK to close launchy settings.
Now let's test it.
- launch launchy with Alt+Space or your hotkey
- type note (You may have to wait 10 second or so on first run. You'll know things are as expected when you see the text "note" with a orange/yellow icon containing silhouette of a person.)
- hit Tab
- enter some text (no need for single or double quotes or escapes), e.g.: Remember to donate at least $3 to Josh at Launchy https://www.launchy.net/donate.php
- hit Enter
Now open collectednotes.md to confirm the text was captured.
The remaining issues seem to be dealing with single quotes and double quotes. For example, consider the following note:
I don't know what I'd do without Launchy.
Which results in the following in collectednotes.md:
I dont know what Id do without Launchy.
Or:
Would David Allen like universal text capture from anywhere in Linux? My bet is "yes!"
Results in the following in collectednotes.md:
Would David Allen like universal text capture from anywhere in Linux? My bet is \yes!\
Single quoting and/or double quoting the input to launchy doesn't solve it. Note the launchy Runner custom plugin construction component of '$$' is a piece of this puzzle.
I'll give the answer to anyone that can adjust this process (via note.sh and/or launchy plugin setup) to appropriately handle all special characters. Maybe this would add proper escapes to user input with something like gsub.
The rationale for being exacting regarding proper character handling is that this process is useful for copying and logging random chunks of text from web pages, but if common characters like single quotes are not handled as expected, confidence in the system is much reduced.

what is the meaning of shell title?

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

How do I get GNU screen to read .bash_profile/.bash_rc changes?

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"

How do I reveal a file as "selected" in *nix from the command line?

Is there a semi-universal mechanism by which to reveal files as selected in various *nix window managers via the command line? For example, in Windows I can say the following:
explorer.exe /select,C:\TestDir\TestFile.txt
…and Explorer will reveal the file and select it for you. In OS X I can say the following:
osascript -e 'Tell application "Finder" to reveal "MacHD:Users:myaccount:Desktop:filename.txt"'
…and it will do the same. My question is, is there any way to do the exact same thing (somewhat universally) in any of the various popular *nix flavors across window managers? Obviously "Open Containing Folder" is simple enough, but I want to go the extra step of actually opening it with the specific file selected. Any assistance is appreciated.
Best.
I don't about other file managers (other answers can add that) but for nautilus it's been recently fixed
This allows to call nautilus
uri:///path/to/file from the command
line to open uri:///path/to with file
pre-selected.
For OSX AppleScript works for all versions, but if you know you'll be dealing with 10.6 or later you'd be better served by using the -R option for "open". It's around 30 times faster.
open -R "/Volumes/Users/Desktop/file-to-open.txt"
For Linux Nautilus allows for direct calling of the file, a generic solution for GNOME (you won't find one for "Linux") is the "gnome-open" command, which currently could open the directory but won't highlight the file:
"gnome-open /tmp/file.txt"

Can you rename a shell session by command in linux?

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

Resources