Hacker News new | ask | show | jobs
by dfc 4696 days ago
Do you know anyone with a 10k .bashrc?
3 comments

My apologies, I was being a little facetious. Just a little. :)

The size difference was based on my intuition that when I maintained my own .bashrc and .zshrc, I was able to "get away" with fewer total lines in my .zshrc than my .bashrc. I remember my .bashrc being dozens of pages, my .zshrc was only a couple.

Compare that to my fish init file...all it does is set a few paths and aliases and turn off the greeting, because everything else just works out of the box for me.

I just checked, for fun:

    $ ls -lh .bashrc
    -rw-r--r--    1 <me>    <me>         10k Jul 26 13:31 .bashrc
Yep.

It's also remarkably fast because I took great effort to optimize the parts that happen the most. Shell is actually pretty fast if you don't fork and exec all the time...

What do you have in it that takes up so much space? FYI: I'm not being argumentative, I am genuinely curious.
Well, it's about 400 lines total. Roughly 40% of that is PATH handling functions: add_to, append_to, replace_in, remove_from, prefix and unprefix. They're used like:

    add_to PATH /usr/sbin
prefix and unprefix are a macro for a bunch of standard replace_in/remove_froms:

    prefix() {
        replace_in PATH "$1/bin"
        replace_in PATH "$1/sbin"
        replace_in PATH "$1/lib/ccache"
        replace_in MANPATH "$1/share/man"
        replace_in MANPATH "$1/man"
        replace_in PKG_CONFIG_PATH "$1/lib/pkgconfig"
    ...etc.
So that later I can do stuff like:

    prefix /usr/local
    prefix /usr/local/brew
    prefix /usr/local/ports
...All of which are managed by different package managers (stow, brew, ports).

All that stuff is the part I optimized so that it only uses bash built-ins and never execs. Converting that away from sed/perl shaved about 8 seconds off my startup time (it's now so fast I don't notice it).

The next 20% is interactive stuff. Setting up the prompt, aliases, stty, etc. This is generally more complicated than it technically needs to be because it's cross platform so it'll run on any unix-y thing with no changes.

Then remaining 40% is a big chunk of shell functions that are mostly unused in my day-to-day life, but kept there to jog my memory if I need to do a certain task.

That adds up to 100%, but it's also worth noting that 27% of that is blank lines and comments.

I know people with well more than that, particularly when you factor in 'oh my zsh' and its ilk.
I am not sure I would include oh-my-zsh as someone's personal zshrc. Moreover I thought OP had made a distinction between bash (10k) and zsh (1k) so I am not sure how o-m-z counts as a bashrc? I will take your word for it but I cant imagine what people put in there bashrc to get to 10k. The entire bash-it repository is 8,588 and over a third of it is bash completions which seems to duplicate the majority of what is already provided by bash-completion. And I am not sure that bash-completion is really "my .bashrc."

  $ cd bash-it
  $ sloccount ./ 
  ...SNIP...
  SLOC    Directory       SLOC-by-Language (Sorted)
  3198    completion      sh=3198
  3168    plugins         sh=3168
  1081    themes          sh=1081
  748     lib             sh=748
  242     aliases         sh=242
  135     top_dir         sh=135
  16      template        sh=16
  0       custom          (none)


  Totals grouped by language (dominant language first):
  sh:            8588 (100.00%)

Are there some big bashrc customizations that I might be overlooking?

edited to reflect distinction between parent and grandparent comment

Sorry, I'm not the parent commenter.