Having recently migrated from a PC to a Mac, I've been missing some home comforts from Powershell. One of my favourite things was PostGit, which provides in-line Git information relating to your current folder.
Since moving to Terminal on the Mac, I found my productivity had dropped significantly as little issues got in my way.
Here are a few code snippets I've found which help improve Terminal's usability.
Set Auto-complete to be case insensitive
echo "set completion-ignore-case On" >> ~/.inputrc
By default, tab completion is case-sensitive, so this snippet adds a property to the .inputrc file (and creates the file too) to ignore case. To revert. just modify the file in your favourite code editor and remove the line.
Akin to Chocolatey in Windows, Homebrew is a command-line utility that allows you to install additional tools and packages from a remote repository.
To install, paste the following code into terminal and hit enter:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
As the heading suggests, this package provides auto-completion for Git commands, and just makes writing commands that bit quicker
What this provides is a colour-coded in-line summary of the git status of the current directory, including which branch is checked out and whether you're up-to-date with your remote.
Follow the readme and install
Once you've installed these things, your .bash_profile & .bashrc files should look similar to the samples below. You may not be able to be able to see the files in Finder, so use the
code command in Terminal to open them in VS Code, or turn on ShowAllFiles and double-click them once they appear in finder (See below on how to launch VS Code and show hidden files).
Your .bash_profile file should include sections for bash completion and referencing the .bashrc:
if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fi source ~/.bashrc
Your .bashrc file should include these lines:
source ~/git-prompt.sh PROMPT_COMMAND='__posh_git_ps1 "\u@\h:\w " "\\\$ ";'$PROMPT_COMMAND
Turn on 'code' command to launch VS Code
In VS Code hit: CMD + SHFT + P then type the following (auto-complete should help):
Shell Command: Install 'code' command in PATH
Once enabled, you can open a file by typing:
or if you want to open the folder at your current location you can use:
Show hidden files
Something that's related more to Finder than Terminal, but is a bit obscure to find is how to show
defaults write com.apple.finder AppleShowAllFiles YES
Make 'tab' cycle through options
When pressing tab, the default behaviour is to auto-complete if the terminal can only find one option that matches the current input, or display all options if more than one match is found. However, in Powershell, you can cycle through the various options until you find the one you want. To achieve this in Terminal open your ~/.bashrc file in VS Code and enter the following:
Hit save and reload your terminal. You should now be able to cycle through items using tab.