
Show HN: Sensible Bash: An attempt at saner Bash defaults - mrzool
https://github.com/mrzool/bash-sensible
======
thom_nic
I feel like discussion of 'sensible bash defaults' is incomplete without
mention of .inputrc. My most "can't live without it" setting for bash is
actually an .inputrc setting:

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

... so if I type `ssh <up arrow>` I get the last command that started with
`ssh`, not the last command I ran. oh-my-zsh thankfully does this by default
as well. But I still use my .inputrc on server boxen where I don't want/need
to install a different default shell.

Also worth noting that all of those `bind` commands in OP's script are
actually .inputrc lines if you remove the `bind` and surrounding quotes.

~~~
ajross
This is why these things are so personal. I'd hate this. The up/down bindings
are __absolutely __tied to specific command orders in my head. I need to know
that "three commands back" is wherever I was in the sequence of commands that
I'm repeating.

If I'm trying to semantically query my history (for "ssh") in this case I'll
use the ^R binding to incrementally search the history, or literally grep
~/.history for what I'm looking for.

That's not to say that you're "wrong", just that calling these things
"sensible defaults" is sort of missing the point. Nothing about them is
sensible for everyone.

~~~
omalsa04
If you just press "up" without typing anything first then it works as you
expect. I find ^R annoying if I've already started typing the command and then
realise I can search the history (although that's probably configurable).

Once you get used to it, the only downside of up/down history search is when
you ever use a shell that doesn't do it and you feel lost.

~~~
zo1
On a standard Ubuntu install: If you press ^R after already typing part of
what you're searching for, and then press a key (space, or more of the command
you're searching for), then it'll switch to the history-search mode with that
value pre-filled in.

------
wyldfire
> Prepend cd to directory names automatically, so you can cd into directories
> just by typing their name;

I'm pretty sure this is a solution to a problem I don't have today.

> Treat hyphens and underscores as equivalent;

> Automatically correct spelling errors during tab-completion;

I'm terrified to put this in my shell. Then again, it's not all-or-nothing:

> cherry-pick the options you like most ... everything is open for discussion

~~~
hornetblack
> > Automatically correct spelling errors during tab-completion; > I'm
> terrified to put this in my shell.

I had it in once (it's one the options in zsh setup)

Once I was cleaning my home directory:

    
    
        rm -rf tec<Tab>
        rm -rf IdeaProjects<Ret>
    

I'm a bit too quick to press enter after tab. So i deleted the wrong folder.

I do still have it auto correct case. So `doc<Tab> -> Documents`

~~~
alphapapa
This is why I delete to trash, even from a terminal. I use the trash-cli
package on Debian/Ubuntu.

Also:

    
    
        alias rm 'rm -i'

~~~
zurn
-f overrides -i unfortunately.

(trash-cli sounds good, thanks for the tip)

------
rout39574
May be an old-fart prejudice, but my eyes cross to think that 'dash and
underline are equivalent' might be a desired thing. Making bash be clever
seems like a pile of pitfalls.

To each their own.

~~~
bpchaps
Yeah, I don't get this one, either. This seems far away from sane.

What's the rationality behind it?

~~~
mrzool
I don't have any file or folder name starting with a dash, while underscores
are pretty common. Treating dashes and underscores as equivalents saves you
one keystroke (i.e. you can type `cd -folder<tab>` instead of `cd
_folder<tab>`).

~~~
wyldfire
You mean it saves you one edit in the case where you've mistyped the directory
name? Otherwise it seems like no keystrokes are saved among the two you show.

EDIT: groan, ok, you win. Net -1 keystroke for most keyboards.

~~~
mrzool
The shift press doesn't count as keystroke? :)

------
dlitz
It would be nice if bash had a more discoverable version of the 'help' command
for new users.

Right now, someone (say, a bright 12-year-old) who opens up a terminal for the
very first time and types "help" is greeted with this lovely mess:

    
    
         compgen [-abcdefgjksuv] [-o option]  >  return [n]
         complete [-abcdefgjksuv] [-pr] [-DE] >  select NAME [in WORDS ... ;] do COMM>
         compopt [-o|+o option] [-DE] [name ..>  set [-abefhkmnptuvxBCHP] [-o option->
         continue [n]                            shift [n]
         coproc [NAME] command [redirections]    shopt [-pqsu] [-o] [optname ...]
         declare [-aAfFgilnrtux] [-p] [name[=v>  source filename [arguments]
         dirs [-clpv] [+N] [-N]                  suspend [-f]
         disown [-h] [-ar] [jobspec ...]         test [expr]
         echo [-neE] [arg ...]                   time [-p] pipeline
         enable [-a] [-dnps] [-f filename] [na>  times
         eval [arg ...]                          trap [-lp] [[arg] signal_spec ...]
         exec [-cl] [-a name] [command [argume>  true
         exit [n]                                type [-afptP] name [name ...]
         export [-fn] [name[=value] ...] or ex>  typeset [-aAfFgilrtux] [-p] name[=va>
         false                                   ulimit [-SHabcdefilmnpqrstuvxT] [lim>
         fc [-e ename] [-lnr] [first] [last] o>  umask [-p] [-S] [mode]
         fg [job_spec]                           unalias [-a] name [name ...]
         for NAME [in WORDS ... ] ; do COMMAND>  unset [-f] [-v] [-n] [name ...]
         for (( exp1; exp2; exp3 )); do COMMAN>  until COMMANDS; do COMMANDS; done
         function name { COMMANDS ; } or name >  variables - Names and meanings of so>
         getopts optstring name [arg]            wait [-n] [id ...]
         hash [-lr] [-p pathname] [-dt] [name >  while COMMANDS; do COMMANDS; done
         help [-dms] [pattern ...]               { COMMANDS ; }
        user@host:~$

------
burgerdev
Most of these are included in /usr/bin/fish :)

~~~
heydonovan
Came here to say this! Got tired of the little quirks, and never looked back.

~~~
alphapapa
Yep, for interactive use, Fish is fantastic. Bash is still a better choice for
most shell scripting though.

Also recommend using something like Percol or fzf for filter-as-you-type
command history.

------
otobrglez
Hey guys! If you are interested in "different" shells and REPLs I suggest you
check out Ammonite-REPL / Ammonite-Shell
-[http://www.lihaoyi.com/Ammonite/](http://www.lihaoyi.com/Ammonite/) It's
written in Scala and well. It looks ql. :)

------
sapht
This looks pretty sane overall. If you try this, be aware that it changes
directory navigation, i.e. "Prepend cd to directory names automatically, so
you can cd into directories just by typing their name", "Automatically correct
spelling errors in arguments supplied to cd". I've tried these things and they
drove me insane, so they're not good defaults for everyone.

------
onli
I like it. It is not a complete revamp of bash to something else (the zsh-
comment below is not fitting), it just enables some comfort features bash
readily supports. One can argue about the case-insensitivity, but I see no
other option that could be controversial. Just a small collection of sane
defaults.

------
technimad
In other words: making bash more like zsh

~~~
jjawssd
Came here to say the exact same thing.

Get zsh today. Give it a spin.

~~~
aerique
Or fish, which is basically zsh with sane defaults.

~~~
coldtea
Or bash, since it will be installed everywhere, you don't have to get it, and
most scripts you'll find online will work on it.

~~~
MikeKusold
This is a non-issue. The `!#/bin/bash` at the top of scripts will tell the
interpreter which shell to run. And any one liner I've found online for bash
has also worked on zsh (for me), but even if it didn't: `bash -c ls`

~~~
aerique
Yes exactly.

Today I learned people actually write / use scripts without specifying the
interpreter at the top of the script. This is like writing a Ruby script and
expecting it to work when calling it with the Python interpreter.

------
modeless
These history settings should clearly be the real defaults. I wonder how
difficult it would be to get them changed upstream?

Upstreaming would also allow improvements, for example PROMPT_COMMAND='history
-a' doesn't update history until the next prompt is displayed. If you close
your terminal while a program is running then the last command entered is not
saved.

------
ChrisArgyle
Some great ideas here--a lot of them solve problems I've personally had with
bash over the past 15 years--but plenty of these feel like solutions in search
of problems.

I'm tempted to post my own commentary but I'd probably make the same mistakes.
What would be really fantastic is a usability study of bash to see what the
common pain points are.

------
riquito
Does anyone know if bashscript could be updated to allow spaces between
assignment? I can't see how it would break existing programs (but I'm sure
there's a catch) and scripts would be much cleaner (and less of an headache).

~~~
opejn
A breaking example might be trying to find lines containing an "=" in a file:

    
    
        grep = my_file
    

Also a problem is the syntax for running a program with environment
assignments that apply only to the program:

    
    
        env1=foo env2=bar env3= my_program
    

Note that under POSIX rules, "env3" here is assigned a zero-length string.
Making these sorts of assignments work with spaces around the equal signs
would open up a can of worms.

------
ymse
Minor nitpick: why is the session history larger than the maximum file size?

It always annoyed me that HISTTIMEFORMAT is not set by default. Without it,
log entries are simply not timestamped at all.

The readline tweaks were news to me, thanks.

~~~
LukeShu
HISTFILESIZE is kind of a misnomer. It's the maximum number of _lines_ in
HISTFILE, where HISTSIZE is the maximum number of _commands_. If you have
HISTTIMEFORMAT set, then each command gets at least 2 lines, plus the
possibility of multi-line commands.

------
rejap
a lot of this stuff is present in cygwin but by default commented out.
Something what made me more productive is a cd_func:

out of .bashrc:

function cd_func

This function defines a 'cd' replacement function capable of keeping,

displaying and accessing history of visited directories, up to 10 entries.

To use it, uncomment it, source this file and try 'cd --'.

acd_func 1.0.5, 10-nov-2004

Petar Marinov, http:/geocities.com/h2428, this is public domain

~~~
LukeShu
I've got `alias cd=pushd` in my .bashrc. It keeps track of visited directories
as a stack (arbitrarily deep).

------
Gratsby
Sensible Bash... like Fish or Z Shell?

~~~
startling
fish is not even a sh, much less a bash.

~~~
Gratsby
That's true, but everytime I say the words z shell, someone always says
"Fish!", so I figured I'd pre-empt them for once. Go figure it would backfire
on me. LOL.

------
LASR
Or just use fish. Why is this even a conversation in 2016?

------
justin_vanw
I thought 'sensible bash' was called zsh.

Just kidding, but not really, zsh is great and basically compatible with Bash,
check it out.

