grc icon indicating copy to clipboard operation
grc copied to clipboard

Idea: Simplify bash and zsh initialization

Open f6p opened this issue 3 years ago • 2 comments

Hello,

I was setting up grc on my system and I can't stop thinking that there may be way to simplify default alias setup. If both bash and zsh wouldn't use shell specific code both could source same init file or eventually grc.zsh could be link to grc.sh. On my system I do this with code like below:

for config in /usr/share/grc/conf.* ; do
    config=${config##*.}

    if command -v $config &> /dev/null ; then
        alias $config="colourify $config"
    fi
done

unset config

alias colourify='grc --colour=auto --stderr --stdout'
alias configure='colourify ./configure'
alias ls='ls --color=auto'

That would result in de-duplicated config for both shells. Obviously this example iterates over dir contents but could iterate over list of commands instead.

Also code could be packed into functions like grc_colourize_defaults - this one would colorize what grc.sh already does by default and grc_colourize_everything - that would iterate over contents of each: ~/.grc/, /usr/local/share/grc/ and /usr/share/grc/ similar way to this in the code above. Then to colorize all user would only need to put grc_colourize_everything in user's bashrc or zshrc before setting any other aliases.

It this idea has any merit I can try my take on it and work on PR. Please let me know what you think.

Cheers 🍷

f6p avatar Mar 30 '21 10:03 f6p

I use ZSH but I just load /etc/grc.sh on .profile. (BTW it's /etc/profile.d/grc.sh on Arch.) Later I load my aliases and have some like alias journalctl='journalctl' to disable the ones I don't want.

danisztls avatar Apr 18 '21 20:04 danisztls

@lbcnz Yes thats probably a good point - one can directly load grc.sh instead of grc.zsh.

But still not all possible aliases are defined there and there is no check if aliased command is actually available in the system (like lets say docker).

f6p avatar Apr 19 '21 07:04 f6p