On my bash prompt, I would like to see just the name of the current directory followed by "$" in different colours.
So I used this code but when I have a long typed command, I see the cursor in different place than where the typing is taking place. How can this "hard to describe" problem be fixed? Thanks
PS1='\[\e[0;36m\]\W\[\e[m\]\[\e[1;31m\]\$\[\e[m\]'
Use a carriage-return after outputting the current directory, I've done this for years and it works a treat, something like:
if [ "$PS1" ]; then
PS1="\[\e[0;36m\]\W\n\[\e[m\]\[\e[1;31m\]\$\[\e[m\]"
fi
You always have your current directory (no matter how long) on top of your $ prompt.
I put other info up there as well like username, machine name and exact time and date. I colour them differently so they really stand out. Helps if you have multiple sessions going on, on different machines with or without root(!) privileges (have to be root when deploying a complete rebuild). And has saved the day many times when I need to know when I did something or other (ok, it's when that task ended - but still helps).
But most of all, it's great to know your current directory by simply looking at your command line prompt :) )
Don't know how other people work efficiently without it!
Related
As soon as I try to access a folder/file containing an emoji in its name from my Lua 5.2 script, for example like this:
os.execute('start "" "' .. path .. "\\scripts\\menu\\📄 My Scripts" .. '"')
The Windows' Command Prompt simply refuses to open it with the following error message:
I'm aware Windows' Command Prompt doesn't support emojis and therefore is not possible to make it work just like that, but my doubt is if won't exist some workaround or whatever I can do to ensure any Windows/Unix user is going to able to get the folder open by my Lua script without any problem.
I have tried i.e. things like use the codes instead (1246 and U+1F4F0 in this page facing up case) without success. Couldn't I for example simply use some kind of "wildcard" instead? I mean, knowing it's always going to be the very first character in the name. Or, well, any other ideas will be welcomed, cause nothing I'm trying really seems to work...
Of course if it's going to represent any problem I'll simply refuse to use them, but it came in handy for some "first sight" folder distinction and, if possible, I'd like to can count this little visual resource 🙄
This is a Problem about how the string is constructed.
I found only one solution with [[command "path"]] (on Windows 11 and Lua 5.3)...
os.execute([[start ]] .. path .. [["\scripts\menu\📄 My Scripts"]])
-- My Testpath is/was: os.execute([[dir "%localappdata%\nvim\📄 Lua"]])
...the long string ([[]]) will not be interpreted (coercionated) by Lua.
That also have the side effect that you can use single backslashs with that kind of string.
Environment variable expansion (e.g. Windows: %localappdata%) only works inside doublequotes.
Single quotes instead ([[command '%localappdate%\path\']]) will not work (expanded).
os.execute accepts only ANSI-encoded strings (win-1252 in European Windows), but it is unable to encode an emoji.
Hint: you can create .bat-file to do the task for you and invoke it from Lua with os.execute.
My shell is GNU Bash 4.3.11, and I currently have M-h bound to cd .. by calling the builtin
bind -x '"\eh": "cd .."'
This gives me a nifty way to navigate up the directory tree, as I can repeatedly hit M-h instead of the incredibly time-consuming cd ... It has the downside, however, either of not resetting my $PS1 or of not redrawing my prompt, so I lose the context of my current working directory until I enter a new command.
One alternative I'm aware of is to put a macro like
"\eh": "\C-a\C-kcd ..\C-m"
in my .inputrc directly. This, however, has the downside of not only losing the context of any existing command I'm typing in (which I think can probably be worked around) but also of printing out cd .. (which I don't think can be).
My desired behavior is to be able to be in a directory ~/one/two with prompt ~/one/two$; hit M-h; and then be in ~/one and have the prompt be ~/one$, ideally keeping any command I had initially. How can I achieve this?
Figured this out.
# maintain state
bind -x '"\200": TEMP_LINE=$READLINE_LINE; TEMP_POINT=$READLINE_POINT'
bind -x '"\201": READLINE_LINE=$TEMP_LINE; READLINE_POINT=$TEMP_POINT; unset TEMP_POINT; unset TEMP_LINE'
# "cd .." use case.
bind -x '"\206": "cd .."'
bind '"\eh":"\200\C-a\C-k\206\C-m\201"'
I'm quite late to that party - and came here looking for that answer also. First of all: As you were the only one providing information on this: thanks for not letting it come to this: https://xkcd.com/979/ ;) instead you pointed me to the on corner in that fractal that seems to hold a solution.
This approach, in my opinion backed up by hours of trying, is the only one where you can a) replace content on the line, and b) execute bash code. Let me offer up some more suggestions to a specific problem:
If you are trying to have it both ways: insert something on the command line, or executing code, things can get very tricky. for both, there exist bindings, and I let the reader figure out things with help bind. But in the case you e.g. have FZF produce some directory as output, and you'd either cd to it, or have it pasted into your command -- depending on the keystroke done in FZF -- things will get near impossible. you'll face either the not-updated-promt problem, or not be able to execute the cd command in the top shell (where it has effect).
Your solution would be a multiplexing -x binding, inspecting the output for "macros" (get extracted and eval'd) or the default pass-through (manipulating READLINE_LINE/POINT).
Because the solution has some enormity, and the audience may be limited (closed answer...), I'll leave it at a haphazard gist where I pasted my code which works now. To make up for the brevity and uncommented-ness, I welcome any questions in comment or elsewhere. Hope someone may be pointed in the right direction.
- The code related to this question starts in function bindInsertEvalWithMacrosVi
- It is designed for Vi keybindings but the same principles apply for normal readline mode
- It depends on some \C-x\C-... combinations to do redrawing in places that are not related to this post.
https://gist.github.com/simlei/032470cfcd23641987f97a96749128d7
Is there any way to have ksh display the current typing mode at the bottom of the window like vim; like "Insert", "Command", "Visual", etc? Unfortunately, I am having a lot of trouble remembering which mode I'm in and find the shell unintuitive (at least until I get used to all the commands). I consistantly hit the wrong key in command mode and have difficulty figuring out how to get back to proper typing (sometimes it lets me type but not delete part of the line and I don't know why).
I am required to use ksh for work and am heavily restricted in what I can download and install, but I need to figure this out. Hopefully there is something I can do with a profile or script along these lines to help ease the transistion. Also, this is HP-Unix, in case that affects anything.
This set -o alone command will show if emacs is defined to on
$ set -o|grep emacs
emacs on
Now i try find the way to prove that a clear command is working correctly on my own REPL
Example
$ cd ~
$ pwd
/home/user
$ echo "hello"
hello
then type clear
$
but sometime some unexpected behavior is occurred after using a clear command
e.g.
[one blank line here]
$
A one blank line after using clear command is undesirable behavior and I hope this kind of bug can be detected automatically via a unit test. If you have any idea to prove that clear command is working correctly please purpose.
There is no easy way to do this. "clear" sends a sequence of bytes that tells the terminal to clear its screen. Different terminals use different sequences. There is a table called "termcap" (terminal capabilities) that lists the difference sequences for different types of terminals. The environment variable "TERM" should be set to the type of terminal you are using.
TERM is usually set to "xterm", "xterm-color", "vt100", or related value. On my Mac OS X Terminal it is set to "xterm-256color".
TERM should be set automatically for you. If your OS is set up properly you shouldn't have to set it yourself. However in the old days you had to set it manually. Therefore you'll find a lot of old .profile/.bashrc/.cshrc files that set it. Check to see if that is happening and remove that (comment it out) to see what is automatically set.
Your question boils down to "how can I tell if my TERM variable is set right?" and the answer is: You can't. You could do things like clear the screen then ask the user if they saw their screen clear. However, if programs did that on start-up, it would be very annoying.
The following script works, but I need help with one change. Right now using lday serach, and a little utility called GETPASS, this script will pull a listy users, from a specified context out of an LDAP directory, compare their LDAP password, to an unused attribute, If different, add it to the unused attribute called carLicense, and then send it in SHA 1 format, up our google APPS domain, with Google Apps directory sync. The one problem, is that it when it returns the ldapsearch, it works fine with a user in this format:
cn=joebloe,ou=googletest,o=someorg
However, if the usename has a space in it like this:
cn=joe bloe,ou=googletest,o=someorg
the script will fail as it does not know how to deal with that space. In this situations, a single quote, around the DN will solve the issue IE:
'cn=joe blow,ou=googletest,o=someorg'
However, I have tried to alter the script to address this need of mine, and I am failing miserably, please see a copy of the script in Pasetebin below. Any help with be deeply and GREATLY appreciated, as this is currently my only stumbling block to success.
http://pastebin.com/htWxsNXj
Replace the first line of generating result file (in your pasting is line 66) with:
echo "dn: '$RESULT'" >> $SCRIPTPATH/gadspwsync.ldif
If it won't help, don't remove the file in line 75. Check the content, show us the first line, then show the expected content.