Giter VIP home page Giter VIP logo

bash-sensible's Introduction

Sensible Bash

An attempt at saner Bash defaults. Inspired by Tim Pope's sensible.vim.

The config

Sensible Bash is intended to be a simple starting point for a better Bash user experience out of the box.

Refer to the commented source for a complete list of all the options with explanations. Here's a taste:

Smarter tab completion

Readline bindings to improve on Bash's default tab completion:

  • Perform file completion in a case insensitive fashion
  • Treat hyphens and underscores as equivalent
  • Display matches for ambiguous patterns at the first press of the tab key (instead of requiring two tab-presses)

Saner history defaults

Sensible defaults for the command history:

  • Append to the history file instead of overwriting it
  • Save multi-line commands as one command
  • Record each line as it gets issued
  • Keep track of a bigger history
  • Avoid duplicate entries
  • Avoid recording unneeded commands (exit, ls, bg, fg, and history itself)
  • Use a standard ISO 8601 timestamp for recording commands (ex: 2016-04-09 13:06:31)

Read more about the settings used here in the article Better Bash History by Tom Ryder.

Faster file system navigation

Options that considerably speed up the ability to navigate throughout the file system:

  • Prepend cd to directory names automatically, so you can change to a directory just by typing its name
  • Automatically correct spelling errors during tab-completion and in arguments supplied to cd
  • Set more targets to the cd command besides the current working directory (ex: projects, repos, documents, etc)
  • Define paths as variables and cd into it from anywhere, kind of like a bookmarking system for Bash (cdable_vars)

Usage

You can copy sensible.bash in your bashrc, cherry-pick the options you like, or source the file at the top of your bashrc:

if [ -f ~/bin/sensible.bash ]; then
   source ~/bin/sensible.bash
fi

Caveats

In order to get Sensible Bash to work correctly, make sure that:

  • You're running at least Bash 4.x (echo $BASH_VERSION).
  • You have the Bash Completion package installed and properly configured on your system.
  • If you're on macOS, I recommend to follow Josh Staiger's advice and source bashrc from bash_profile so to keep all your configuration in one place.

See also

License

MIT

bash-sensible's People

Contributors

btoll avatar derekgottlieb avatar joegrandominico avatar kylescottmcgill avatar lookfirst avatar mrzool avatar paulmolluzzo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bash-sensible's Issues

Disabling terminal freezes because of scroll lock (XOFF)

What about disabling scroll lock (XOFF), to avoid people puzzling why the screen is frozen, having to find out about Ctrl-S and scroll lock and hitting Ctrl-Q to "unfreeze"?

I've been using this for years in my bashrc, but I don't know how portable it is:

# disable terminal locking
bind -r '\C-s'
stty -ixon

Suggest Bash upgrade for OSX users.

You might want to update your readme.md to suggest that OSX users upgrade to bash 4.x

This worked for me (obviously need homebrew installed first).
brew install bash;echo /usr/local/bin/bash|sudo tee -a /etc/shells;chsh -s /usr/local/bin/bash

Up-to-date Bash on OS X

What is the recommended version of bash-completion?

  • Mac OS X 10.11.3
  • bash 4.3.42(1)-release (via brew install bash)

With bash-completion 1.3 (brew install bash-completion), I'm getting the following error:

-bash: shopt: dirspell: invalid shell option name

With bash-completion 2.1 (brew install bash-completion2), I'm getting the following errors:

-bash: shopt: dirspell: invalid shell option name
-bash: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: complete: -D: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...]

Why is HISTIGNORE exported?

Just wondering why HISTIGNORE is exported while none of the other variables are.

My inclination is to say HISTIGNORE should not be exported since it seems bash specific and subprocesses won't use it.

Some additions

I'll try to contribute in free-form style:

  • set -o noclobber
  • shopt -s checkwinsize
  • stty -ixon
  • PROMPT_DIRTRIM=2
  • . /usr/lib/git-core/git-sh-prompt
  • show the last command exit status message: PROMPT_COMMAND='_status=$?; [[ $_status == 0 ]] || echo -e "\e[4mExit status: $_status\e[m"; '$PROMPT_COMMAND

Suggested resource

I wanted to point out to you and perhaps anyone else to mathiasbynes dotfiles. Its a great community maintained set of configs. It has a much larger scope than your project, however it may be a great resource for you to draw on a "sensible" set of options. Or just a place to point people to when their suggestions fall outside "sensible" defaults.

In particular:

more readline/ inputrc options

I tend to use a separate .inputrc file but you can of course put these in bind commands like you're already doing from the bashrc... Here are two of my favorites:

# From http://www.ukuug.org/events/linux2003/papers/bash_tips/
# Incremental searching with Up and Down
"\e[A": history-search-backward
"\e[B": history-search-forward

e.g. so typing ssh <up arrow> searches through prior ssh commands rather than your entire command history.

Place binds in a tty detection block?

When I scp to a host that I've added the sensible.bash to my ~/.bashrc, I see bind warnings.

/home/matt/bin/sensible.bash: line 28: bind: warning: line editing not enabled

I placed the binds in a TTY detection block like explained here: https://superuser.com/questions/892658/remote-ssh-commands-bash-bind-warning-line-editing-not-enabled

if [ -t 1 ]
then
  # standard output is a tty
  # do interactive initialization

  # Enable history expansion with space
  # E.g. typing !!<space> will replace the !! with your last command
  bind Space:magic-space
  ...
fi

Works well for this.

Split project into "bash-sensible" and "inputrc-sensible"

I love the idea of this project and appreciate the great defaults it gives me. Thank you.

To make the project even better I propose to split the defaults into "bash-sensible and "inputrc-sensible" for two reasons:

  1. Avoid shadowing preferences set in ~/.inputrc (e.g. I have set show-all-if-ambiguous off in my .inputrc which is overwritten by bash-sensible. Thus, I need to set it a second time in .bashrc after loading bash-sensible.)
  2. Make these great defaults also available to other programs that use readline (python REPL, etc).

Timestamp format is not ISO8601

"%F %T" looks like a decent timestamp format to me, but it's not an ISO8601 timestamp, that would be "%FT%T". Suggest you remove the reference to the standard there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.