I've set the keymaps of shell using set -o vi but how do I exit vim mode in shell? Executing :q or anything doesn't seem to work. unset -o vi returns bad option -o
You cannot unset a keymap, you can only change it:
set -o emacs
Because emacs is the default keymap.
Related
I like to use the vi command line editor, however the bash_rc and bash_profile are owned by root. So what is did was create a script that I can run on multiple terminals to set the command line editor to vi. However when I use this script, it says that is sets vi to on, however after running the script, vi is still set to off.
I do not understand.
#!/bin/bash
check_set() {
chckifvi=$(set -o | grep "\bvi\b"| awk '{print $NF}')
}
check_set
echo "VIM command line editing is set to $chckifvi"
if [[ "$chckifvi" == "off" ]] ; then
set -o vi
check_set
echo "VIM Command line editing is set to $chckifvi"
else
echo "VIM Comamnd line editing already set to $chckifvi"
fi
casper#casperfi 1006$ ~/bin/editerSet.sh
VIM command line editing is set to off
VIM Command line editing is set to on
casper#casperfi 1007$ set -o
allexport off
braceexpand on
emacs on
errexit off
errtrace off
functrace off
hashall on
histexpand on
history on
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
noexec off
noglob off
nolog off
notify off
nounset off
onecmd off
physical off
pipefail off
posix off
privileged off
verbose off
vi off
xtrace off
Run . ~/bin/editorSet.sh, not ~/bin/editorSet.sh, to execute the script's commands inside the interactive shell you're already running. (In bash, but not all POSIX shells, you can use source as a synonym for .).
Otherwise, it runs in a new shell which exits when the script does, so the configuration changes do not last past the end of the script's execution.
I have a bash script that I execute with /bin/sh -xe script.sh and I need to capture its output.
The problem is that inside the script I use some ENV variables that I would like to keep them from being displayed in the output.
Is there any way to do this?
Ie. if my script has touch $MY_ENV_VAR and MY_ENV_VAR=ok the output of /bin/sh -xe script.sh will be touch ok.
Is there any way to keep env vars from being replaced in the output of -x? So I would just get + touch $MY_ENV_VAR back.
There is nothing in the POSIX standard which allows this. All you could do is:
set +o xtrace # Switch xtrace off
some hidden code
set -o xtrace # Switch xtrace back on
Alternatively, use the verbose trace instead of xtrace, that's the -v option.
/bin/sh -ve script.sh
By the way, if you are executing with /bin/sh then it is not a bash script, it is a sh script.
I have a bash instance without Readline support, i.e. this bash is invoked with the --noediting option. The reason is that this bash instance is used by another program.
The other program wants to know how this bash would complete the command line and for this it issues compgen commands in the bash shell, e.g.
compgen -o default I
This works perfectly in my bash without Readline support. Here an example: Let's say, we are in a directory with three files:
IMG_1234.JPG
about.html
index.html
The command compgen -o default I prints duly
IMG_1234.JPG
However now I want to switch to case-insensitive completion. Normally I issue in the shell
bind 'set completion-ignore-case on'
and in a bash instance with Readline support everything is as expected: compgen -o default I prints
IMG_1234.JPG
index.html
However in my bash instance without Readline support the bind command does nothing and I still get only the IMG_1234.JPG match.
So, my question is: How can I set case-insensitive completion suggestions (when using compgen) in a bash instance which is invoked without Readline support?
Test program:
#!/bin/bash
set -e
echo "### CASE-SENSITIVE"
bash --noediting <<EOF
compgen -o default I
EOF
echo
echo "### CASE-FOLDING"
bash --noediting <<EOF
bind 'set completion-ignore-case on'
compgen -o default I
EOF
Result:
### CASE-SENSITIVE
IMG_1234.JPG
### CASE-FOLDING
bash: line 1: bind: warning: line editing not enabled
IMG_1234.JPG
index.html
Bash version:
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
If your bash version is different, then consider upgrading, as I can't reproduce your issue with 4.3.11. (And you'll probably want to redirect stderr from the bind command; I left it in so you can see it's being executed).
I have a small script that i use to log in to a server. I exchanged the keys.
The default set by the adminstirator is emacs. I got kind of addicted to
the vi key bindings. I can't log in as myself, I have to log in as a group user.
most of the time the first thing that i do is type in set -o vi . SOmetimes I forget and start using the vi key binding, but they work work, then i have to use the emacs key bindings. my muscle memory get messed up. It would be great to just automagically have the key bindings set when i log in with the login script.
anyhow I am trying to add the set command to my ssh script.
This one does not work.
#!/bin/bash
ssh -q -T bighost <<EOF
set -o vi
EOF
~
This one does not work
#!/bin/bash
ssh bighost bash -c "'
set -o vi
'"
This lets me ssh to the host, but the vi is not set as the keybinding.
#!/bin/bash
ssh -t bighost "$(< set -o vi )"
corp_user#bighost:~$ set -o
allexport off
braceexpand on
emacs on
errexit off
errtrace off
functrace off
hashall on
histexpand on
history on
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
noexec off
noglob off
nolog off
notify off
nounset off
onecmd off
physical off
pipefail off
posix off
privileged off
verbose off
vi off
xtrace off
corp_user#big_host:~$
I even tried something like this:
ssh corp_user#bighost "$( < . ~/woogie)
Where woogie has "set -o vi " in it.
Can this be done?
This script works when I use it here:
#!/bin/bash
ssh [host] -t bash -o vi
where [host] should be the host you want to connect to. The -t option for ssh tells ssh to force the usage of a tty. If you don't do that, bash won't behave like a normal interactive shell. The option you were looking for is -o vi which is the same thing you'd give to set. The man page for bash mentions that you can give on the command line the same things you'd give set.
This does not require you to create any file on the remote host.
Use Expect
The easiest way to do this in a way that won't impact the other users who share the remote account is with expect. For example:
expect -c 'spawn ssh localhost; expect "$ "; send "set -o vi\r"; interact return'
This will login and wait for a prompt before attempting to set the vi key bindings, and then turn control back over to you.
When I run the /bin/bash process with 2 parameters -c and SomeUserInput,
where SomeUserInput is echo $TERM
The output is
xterm-256color
Is there a way I can set the value of $TERM via a command line parameter to /bin/bash so the above invokation of echo $TERM would print something else that I specify?
(Yes, I've done a lot of digging in man bash and searching elsewhere, but couldn't find the answer; although I think it's likely there.)
First of all, since you used double quotes, that prints the value of TERM in your current shell, not the bash you invoke. To do that, use /bin/bash -c 'echo $TERM'.
To set the value of TERM, you can export TERM=linux before running that command, set it only for that shell with either TERM=linux /bin/bash -c 'echo $TERM' (shell expression), or /usr/bin/env TERM=linux /bin/bash -c 'echo $TERM' (execve compatible (as for find -exec)).
Update:
As for your edit of only using command line parameters to /bin/bash, you can do that without modifying your input like this:
/bin/bash -c 'TERM=something; eval "$1"' -- 'SomeUserInput'
Well, you can either set the variable on your .bashrc file, or simply set with the bash invocation:
/bin/bash -c "TERM=something-else; echo $TERM"