Mac Bash doesn't seem to have skip-completed-text variable - macos

While Googling for another bash tip, I found this page on .inputrc http://ss64.com/bash/syntax-inputrc.html, which exactly fixed what I was trying to do (put a trailing / on symlinks to directories), but as I read further, I saw that there was a way to skip completed text as well. "Awesome", I said to myself, "this bugs me about twice a week". So, I put that into my .inputrc as well, but it doesn't work, or even seem to recognize what's going on. After logging out, and logging back in, this is what I'm seeing:
$ tail .inputrc
set mark-symlinked-directories on
set skip-completed-text on
$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.
$ bind -V | grep completed
$ bind -V | grep skip
$
That is, bash doesn't seem to recognize it's there at all... Is there something wrong with the version of bash supplied in Mountain Lion? Anything blindingly obvious I've forgotten to do?

skip-completed-text is new to bash version 4.

The: skip-completed-text is only in bash4.
On my Mac:
$ bash --version
GNU bash, version 4.2.37(2)-release (i386-apple-darwin12.1.0)
If you want install some opensource utilities i recommending you using macports (www.macports.org). Installing macports will give you one command called port and with it you can install things dead simply, like:
$ port install bash
will install bash 4 for you.

Bash v4 won't make it to OSX. Might I suggest zsh, which is not GPL3.

Related

Bash 5 readline vim mode prefixes not showing

.inputrc commands vi-cmd-mode-string and vi-ins-mode-string are not working. No prefix is shown at the beginning of the bash prompt. But the input mode is indeed vim (I can switch between command / insert mode).
I'm on macOS Catalina 10.15.1. I've installed bash with brew install bash (also tested brew install --HEAD to compile locally).
My bash version is 5.0.11. Should be enough for vi-ins|cmd-mode-string that is available since bash 4.4 (https://stackoverflow.com/a/32614367/2058840)
bash --version
GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin19.0.0)
Copyright (C) 2019 Free Software Foundation, Inc.
I've also install readline via brew, but this changes nothing.
My .inputrc :
$if Bash
set editing-mode vi
$endif
$if mode=vi
set show-mode-in-prompt on
set vi-cmd-mode-string bbbbb
set vi-ins-mode-string aaaaa
$endif
What am I missing here? With this bash version, I expect bbbb or aaaa to be shown as the bash prompt prefix.
Ok. Just found out it's not a problem with the homebrew bash version.
My macOS user config still use the default bash version /bin/bash (bash 3) instead of the homebrew one /usr/local/bin/bash.
You can change yours with https://www.howtogeek.com/444596/how-to-change-the-default-shell-to-bash-in-macos-catalina/.
It took me time to understand that because of the bash --version test. This test the version of the first bash accessible in your $PATH. Not the bash used to open your shell.

how to install and where to install bash bc on windows

I do not know how to install and where to install bc on windows
$ bash -help
GNU bash, version 4.4.23(1)-release-(x86_64-pc-msys)
$ bc
bash: bc: command not found
I use git-bash / mingw64 on windows.
please help
GIT Bash uses MINGW compilation of GNU tools. It uses only selected ones. You can install the whole distribution of the tools from https://www.msys2.org/ and run a command to install bc. And then copy some files to installation folder of Git. This is what you do:
Install before-mentioned msys2 package and run msys2 shell.
Install bc using the following command: pacman -S bc
Go to msys2 directory, for me it's C:\msys64\usr\bin
Copy bc.exe to your Git for Windows directory, for me this is C:\Users\\AppData\Local\Programs\Git\usr\bin
Why do you even need bc on a GIT bash?
A typical usage would be:
Prompt>echo $(1+2 | bc) // or something similar
Recently I've found out that double brackets do the thing, even without bc:
Prompt>$ echo $((1+2))
Prompt>3
Edit after first comment
In case you need floating point calculations, you might use awk, as in this example:
Prompt>awk 'BEGIN {print (20.0+5)/7}'
Prompt>3.57143
There are more examples under this URL.

Downgrade perl version on mac

First of all am new to MAC.
Am facing similar kind of issue on Mac where its shipped with V5.28.0 but i have to use perl V5.18.2 for my application. Have installed perl 5.18.2 using perlbrew install 5.18.2 and the installation was successful.
Have two questions here
Where are my default version and other version installed ? Is there any command to know them ? Have already tried checking echo $PATH but no use.
How to set the default version to 5.18.2 ?
Regards
AVK
The default installation location is
/usr/bin/perl
But that might not be where it's located on MacOS. You can find out for sure by running the following:
perlbrew off
which perl
(Restarting the terminal will reactivate perlbrew.)
The build you installed is in a directory under the directory returned by the following:
printf -- "%s\n" "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}/perls"
You can modify the PATH so that perl runs the desired build using
perlbrew switch <name> # Changes it for this shell instance and those created later.
perlbrew use <name> # Changes it for this shell instance only.
You can get the names to use from
perlbrew list
See Switching to the system Perl using perlbrew for switching to the system Perl.
Scripts need to have the correct perl specified on their shebang (#!) line. Scripts installed by the standard Perl module installers will have this set correctly, but you'll need to edit the shebang (#!) line of scripts you've installed manually.
Another option (incompatible with perlbrew) is to use plenv. This lets you run different versions of perl for each directory. After installing with brew install plenv, you'd use it like so:
$ plenv install 5.18.2
$ cd project/needing/old/perl
$ echo "5.18.2" > .perl-version
Poof! Running perl in that directory or any of its subdirectories will use 5.18.2.
Note: if you run a perl script with ./script.pl, which has #!/usr/bin/perl, this should continue to use the perl installed at /usr/bin/perl. However, if the shebang line is /usr/bin/env perl, this should switch to the version specified by the .perl-version file.

Shell builtin - bind

Edit:
This was due to my PS1 Variable being jacked up (refer to answer section for solution).
Issue:
It seems that I am missing a serious concept of the shell builtin bind:
Mac Shell: ~/> $ bind '"4~":"for x in $(); do blah; done"'
# This is my F12 key
Mac Shell: ~/> $ fx in $(); do blah; doneor
This serves no purpose for me other than learning how to use bind.
Note: The or in for along with the ::space:: following for ends up going to the end of the line.
Question:
Can anybody point me in the correct direction as to what I am doing wrong? I checked man bash # shell builtin section and man bind to no avail.
Bash version:
Mac Shell: ~/> $ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)
Copyright (C) 2007 Free Software Foundation, Inc.
Thanks for your time!
This was being caused due to improperly quoted ANSI color schemes in my PS1 variable. Essentially I needed \[ & \] around each color code to prevent a miscalculation of bash prompt length.
Thanks everyone for attempting to help me with this issue.

How to use GNU sed on Mac OS 10.10+, 'brew install --default-names' no longer supported

Under Mac OS 10.10.3, I installed gnu-sed by typing:
brew install gnu-sed --default-names
When I type it again, I get the message:
gnu-sed-4.2.2 already installed
However, even after rebooting the system and restarting Terminal, I still cannot use the GNU version of sed. For example:
echo a | sed ’s_A_X_i’
returns:
bad flag in substitution command 'i'
What should I do to get the GNU version working?
Here are the paths in my $PATH variable.
/Users/WN/-myUnix
/opt/local/bin
/opt/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/Applications/calibre.app/Contents/MacOS
/opt/ImageMagick/bin
/usr/texbin
I'm sorry if my question seems obvious, but I am learning shell scripting on my own and don't quite understand yet how UNIX programs are installed. Any help to use GNU compliant commands (in this case sed, but soon I'll need others as well) on my Mac without causing damage or unnecessary clutter would be greatly appreciated.
Note (2019):
The --with-default-names option is removed since January 2019, so now that option is not available anymore.
When installing, Homebrew instructs on how to adapt the path, if one wants to use sed without the g prefix.
You already have the gnu-sed installed without the --with-default-names option.
With --with-default-names option it installs sed to /usr/local/bin/
Without that option it installs gsed
So in your case what you gotta do is:
$ brew uninstall gnu-sed
$ brew install gnu-sed --with-default-names
Update path if needed...
$ echo $PATH | grep -q '/usr/local/bin'; [ $? -ne 0 ] && export PATH=/usr/local/bin:$PATH
$ echo a | sed 's_A_X_i'
or use gsed as others suggested.
When you install the GNU version of sed for Mac OS X using:
$ brew install gnu-sed
The program that you use is gsed.
So for example:
$ echo "Calimero is a little chicken" > test
$ cat test
Calimero is a little chicken
$ gsed -i "s/little/big/g" test
$ cat test
Calimero is a big chicken
Also, to compliment the use of GNU command tools on Mac OS X, there is a nice blog post here to get the tools from linux:
Install and use GNU command line tools on Mac OS/OS X
$ brew install gnu-sed
$ export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
With these two commands gnu-sed works properly
The sed that ships with OS X is in /usr/bin.
The sed that homebrew installs is in /usr/local/bin.
If you prefer to use the homebrew one, you have two options:
Option 1
Every time you want to use homebrew sed, type
/usr/local/bin/sed
or, preferably
Option 2
Move /usr/local/bin/ ahead (i.e. before) /usr/bin in your PATH in your login profile, like this
export PATH=/usr/local/bin:<other places>
If you need to use gnu-sed command with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc. Just use the following command in your bash or terminal.
export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
--with-default-names didn't work for me on Mac OS X 10.14.2 so I created a symlink named sed to gsed higher in the $PATH
I also created a symlink named sed.1 to the gsed.1 manpage higher in the $MANPATH so man would access the gsed manpage instead of the default sed manpage
this export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
is only valid per terminal SESSIOn as soon as you restart its GONE ( Mojave )
Since the --with-default-names option was removed in Jan. 2019, my hack solution is:
# hack to override mac tools with homebrew versions (ls, sed, etc)
for p in `find "${HOMEBREW_PREFIX}" -type d -name gnubin` ; do
export PATH="${p}:${PATH}"
done
which is a little slow (crawling the dir every login) but works without forcing me to modify my .bashrc for every gnu tool I happen to install with brew.
A slightly faster way to do what #pjz suggests is the following:
for p in $(ls -d ${HOMEBREW_PREFIX:-/usr/local}/Cellar/*/*/libexec/gnubin); do
export PATH="${p}:${PATH}"
done
Of course this assumes every GNU package in brew will always have the same level of directories to get to gnubin.
Alternatively, you can speed up find by adding the -maxdepth 4 flag before -type d to reduce how far it has to do into directories.
When running brew install gnu-sed on latest homebrew it reports at the end:
==> Caveats
GNU "sed" has been installed as "gsed".
If you need to use it as "sed", you can add a "gnubin" directory
to your PATH from your bashrc like:
PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
gnu-sed installs by default as gsed. However, if you look in /opt/homebrew/opt/gnu-sed/libexec/gnubi you'll find a sed command. So following the above instructions to update the path should mean sed runs gnu-sed.

Resources