4

When I turned on vi mode in bash by setting set -o vi suddenly the tab completion was broken, and a literal tab was inserted. How can this be fixed?

6

TL;DR Solve by creating ~/.profile with

if [ -x /bin/bash ]; then
    exec /bin/bash
fi

Long version:
After searching for quite a while I found that on DSM6 bash runs in posix mode (verify with set -o) and tab completion does not work in vi mode in posix mode (bash completion in Posix mode). I tried the proposed solution by adding bind TAB:complete to my ~/.bashrc but that didn't work. I also tried to turn off posix mode with set +o posix and this worked, but only on the commandline and not when set in ~/.bashrc.

So I tried figuring out why bash would start in posix mode by default. I discovered that my login shell was set to /bin/sh (you can find this in /etc/passwd) which is symlinked to /bin/bash (verify with ls -l /bin/sh). In the bash man pages it says that

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well.

so the solution it seems, was changing the login shell to /bin/bash. After I did this I couldn't ssh to my synology anymore, reason: Permission denied, please try again. The cause? Apparently, Synology disallows any other login shells than ash or sh and they patched and compiled this into the OpenSSH binary (why the &*#$% do they think this is a smart idea?!)

So what to do? The proposed solution is to start a new bash session by creating ~/.profile with

if [ -x /bin/bash ]; then
    exec /bin/bash
fi

and now setting set -o vi in ~/.bashrc works as expected. Only problem is that the default profile in /etc/profile is not read anymore, so you have to set a nice prompt (PS1) yourself in ~/.bashrc. You can copy a standard ubuntu ~/.bashrc or you can have a look at the standard PS1 in /etc.defaults/.bash_profile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.