How can I get rid of showing backup files when I use ls command in Mac OS terminal?
I tried alias ls='ls --hide="*~"' in ~/.zshrc but it does not work.
You need to install GNU ls :
brew install coreutils
then you point your ls alias to use GNU ls version.
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.
I am using oh my zsh. I am not able to use some commands which I could do on ubuntu for e.g.. \s in regular expressions. I installed home-brew and then brew install gnu-sed --default-names but still I am unable to used sed command. my $PATH variable is a bit messed up and I am not sure how to correct it. /Users/ishansrivastava/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/opt/X11/bin:/Library/TeX/texbin. What should I do so that I can use all gnu commands without hassle on my Mac? also please give me the list of commands on which I have to use gnu command instead of default for e.g..gsed instead of sed etc
All rely on how you define your path, the first paths you add are the ones that going to be used first, for example:
export PATH="/usr/local/opt/python/libexec/bin:$HOME/Library/Python/2.7/bin:$HOME/Library/Python/3.6/bin:$HOME/node_modules/.bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/share/bin:$PATH:$HOME/projects/go/bin:$HOME/.cargo/bin"
That expands to:
$ echo -e ${PATH//:/\\n}
/usr/local/opt/python/libexec/bin
/Users/<user>/Library/Python/2.7/bin
/Users/<user>/Library/Python/3.6/bin
/Users/<user>/node_modules/.bin
/usr/local/bin
/usr/local/sbin
/usr/local/mysql/bin
/usr/share/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/go/bin
/usr/local/MacGPG2/bin
/Users/<user>/go_appengine
/Users/<user>/google-cloud-sdk/bin
/Users/<user>/projects/go/bin
/Users/<user>/.cargo/bin
/Users/<user>/.fzf/bin
In this case, for example, you can notice I give priority to python2 instead of python3 and after that, if my command is not found it will use /usr/local/bin, then /usr/local/sbin and so on.
In your case just ensure that the parent path of the commands that you want to use as a "priority" is on top, before the other paths.
I'm trying to upgrade m4 from version 1.4.6 (the version that comes with OS X 10.6.8) to 1.4.16. I've installed with homebrew, and I've also built from source into /usr/local/ (and edited /etc/paths to put /usr/local above /usr), but the system version still seems to take precedence.
Specifically, if I type m4 --version', I getGNU M4 1.4.6 , but if I type/usr/local/bin/m4 --versoin, I getm4 (GNU M4) 1.4.16 `. How do I set the new version as the default version?
...ultimately, I'd like to update autoconf and automake. Is there anything else I should know about installing them?
When you type just m4 at the prompt, your shell looks through the PATH variable to locate the command. You just need to prepend /usr/local/bin to your path. For example, in ~/.bashrc, you can simply do:
PATH=/usr/local/bin:$PATH
Note that this may lead to the directory appearing multiple times in the PATH. You can avoid that with something like:
echo $PATH | tr : \\n | grep -q '^/usr/local/bin$' || PATH=/usr/local/bin:$PATH
I know this might be more appropriate at Ask Different, but as I tried adding tags there, there was no vim tag, only macvim. So I figured I might get a better audience here.
In the Terminal, I do the following
$ vim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jan 31 2010 13:33:49)
When I browse to http://www.vim.org, I see a news item
Vim 7.3 released!
How do I update my built-in vim? I would very much like to do it cleanly (i.e. no duplicate installations, or any additional downloads, no macports, etc.)
I considered using Mercurial (as I already use it for other things), as per the instructions here.
$ hg clone https://vim.googlecode.com.hg/ vim
$ cd vim/src
$ make
But I think that would make a duplicate installation. Despite my "clean" requirement as mentioned above, "unclean" solutions are also welcome, since maybe there really is no other way.
If I understand things correctly, you want to install over your existing Vim, for better or worse :-) This is a bad idea and it is not the "clean" way to do it. Why? Well, OS X expects that nothing will ever change in /usr/bin unbeknownst to it, so any time you overwrite stuff in there you risk breaking some intricate interdependency. And, Let's say you do break something -- there's no way to "undo" that damage. You will be sad and alone. You may have to reinstall OS X.
Part 1: A better idea
The "clean" way is to install in a separate place, and make the new binary higher priority in the $PATH. Here is how I recommend doing that:
$ # Create the directories you need
$ sudo mkdir -p /opt/local/bin
$ # Download, compile, and install the latest Vim
$ cd ~
$ hg clone https://bitbucket.org/vim-mirror/vim or git clone https://github.com/vim/vim.git
$
$ cd vim
$ ./configure --prefix=/opt/local
$ make
$ sudo make install
$ # Add the binary to your path, ahead of /usr/bin
$ echo 'PATH=/opt/local/bin:$PATH' >> ~/.bash_profile
$ # Reload bash_profile so the changes take effect in this window
$ source ~/.bash_profile
Voila! Now when we use vim we will be using the new one. But, to get back to our old configuration in the event of huge f*ckups, we can just delete the /opt directory.
$ which vim
/opt/local/bin/vim
$ vim --version | head -n 2
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Aug 27 2011 20:55:46)
MacOS X (unix) version
See how clean this is.
I recommend not to install in /usr/local/bin when you want to override binaries in /usr/bin, because by default OS X puts /usr/bin higher priority in $PATH than /usr/local/bin, and screwing with that opens its own can of worms.... So, that's what you SHOULD do.
Part 2: The "correct" answer (but a bad idea)
Assuming you're set on doing that, you are definitely on track. To install on top of your current installation, you need to set the "prefix" directory. That's done like this:
hg clone https://bitbucket.org/vim-mirror/vim or git clone https://github.com/vim/vim.git
cd vim
./configure --prefix=/usr
make
sudo make install
You can pass "configure" a few other options too, if you want. Do "./configure --help" to see them. I hope you've got a backup before you do it, though, in case something goes wrong....
Don't overwrite the built-in Vim.
Instead, install it from source in a different location or via Homebrew or MacPorts in their default location then add this line to your .bashrc or .profile:
alias vim='/path/to/your/own/vim'
and/or change your $PATH so that it looks into its location before the default location.
The best thing to do, in my opinion, is to simply download the latest MacVim which comes with a very complete vim executable and use it in Terminal.app like so.
alias vim='/Applications/MacVim.app/Contents/MacOS/Vim' # or something like that, YMMV
Like Eric, I used homebrew, but I used the default recipe. So:
brew install mercurial
brew install vim
And after restarting the terminal homebrew's vim should be the default. If not, you should update your $PATH so that /opt/homebrew/bin is before /usr/bin. E.g. add the following to your .profile:
export PATH=/opt/homebrew/bin:$PATH
Note: Previous versions of Homebrew did install to /usr/local, so in that case you have to use /usr/local/bin instead of /opt/homebrew/bin.
A note to romainl's answer: aliases don't work together with sudo because only the first word is checked on aliases. To change this add another alias to your .profile / .bashrc:
alias sudo='sudo '
With this change sudo vim will behave as expected!
On Yosemite, install vim using brew and the override-system-vi option. This will automatically install vim with the features of the 'huge' vim install.
brew install vim --with-override-system-vi
The output of this command will show you where brew installed vim. In that folder, go down into /bin/vim to actually run vim. This is your command to run vim from any folder:
/usr/local/Cellar/vim/7.4.873/bin/vim
Then alias this command by adding the following line in your .bashrc:
alias vim="/usr/local/Cellar/vim/7.4.873/bin/vim"
EDIT: Brew flag --override-system-vi has been deprecated. Changed for --with-override-system-vi. Source: https://github.com/Shougo/neocomplete.vim/issues/401
brew install vim --override-system-vi
This blog post was helpful for me. I used the "Homebrew built Vim" solution, which in my case saved the new version in /usr/local/bin. At this point, the post suggested hiding the system vim, which didn't work for me, so I used an alias instead.
$ brew install vim
$ alias vim='/path/to/new/vim
$ which vim
vim: aliased to /path/to/new/vim
I just installed vim by:
brew install vim
now the new vim is accessed by vim and the old vim (built-in vim) by vi