Effortless Shell Mastery – Easy Extension and Seamless Migration
The motivation for this post is that it is very hard whenever we switch to a new job or improve our environment because I don’t have a clear architecture to manage my shell environment. I will not update my shell very frequently, so most of the time, I need to review my structure and modify it accordingly.

I re-organize my cshell environment and will apply it to other shells, bash, zsh, and others. Here are the components.

File structure
Based on the components, we can have the following file structure. The most important one is entry file, others will be called by entry file. So we may not care the detail of other files, as long as we know how are these files getting involved in the entry file. Mine is just an example from my best practice.
> tree ~/.mysh/
~/.mysh/
|-- alias.cshrc
|-- behaviour.cshrc
|-- style.cshrc
|-- complete.cshrc
|-- corp.cshrc
|-- cshsub
| `-- myecho.csh
|-- my.cshrc
`-- share.cshrc
mysh.cshrc
is the entry file which sources other files ;behaviour.cshrc
defines the ENV variables, controls the tools’ behaviors, etc. ;alias.cshrc
is the file that contains all the command aliases ;complete.cshrc
has the command completion for the current shell ;style.cshrc
defines color, font, etc. which define the emulator’s look ;cshsub
folder has the file that will be used as function in the csh environment ;share.cshrc
is a file that others can source directly to use your settings.
Entry File
Usually, in a new environment, the new team will have a central environment pushed to each individual. And we can build or override on top of the central environment. So the entry file usually is not .cshrc, instead, it might be the user.cshrc, or .cshrc_user, etc.
We may need to create a link to let the .cshrc source the entry file. Like
ln -s ~/.mysh/mysh.cshrc ~/.cshrc_user
Alias Setting
From different environments, some basic tool installation may vary, and also we may need to add paths to $PATH
environment variables. Here I am using a list of “mysh.*” commands in corp.cshrc to customize local basic tool mappings.
alias mysh.gvim '<Current Tool Path based on the Server Environment>'
alias mysh.vim '<Current Tool Path based on the Server Environment>'
alias mysh.jq '<Current Tool Path based on the Server Environment>'
alias mysh.python3.6 '<Current Tool Path based on the Server Environment>'
alias mysh.perl '<Current Tool Path based on the Server Environment>'
alias mysh.dot '<Current Tool Path based on the Server Environment>'
alias mysh.node '<Current Tool Path based on the Server Environment>'
alias mysh.lua '<Current Tool Path based on the Server Environment>'
alias mysh.git '<Current Tool Path based on the Server Environment>'
alias mysh.tmux '<Current Tool Path based on the Server Environment>'
alias mysh.sqlite3 '<Current Tool Path based on the Server Environment>'
alias mysh.tclsh8.6 '<Current Tool Path based on the Server Environment>'
alias mysh.wish8.6 '<Current Tool Path based on the Server Environment>'
alias mysh.display '<Current Tool Path based on the Server Environment>'
alias mysh.animate '<Current Tool Path based on the Server Environment>'
alias mysh.composite '<Current Tool Path based on the Server Environment>'
alias mysh.convert '<Current Tool Path based on the Server Environment>'
alias mysh.identify '<Current Tool Path based on the Server Environment>'
alias mysh.compare '<Current Tool Path based on the Server Environment>'
alias mysh.conjure '<Current Tool Path based on the Server Environment>'
alias mysh.montage '<Current Tool Path based on the Server Environment>'
alias mysh.jupyter '<Current Tool Path based on the Server Environment>'
alias mysh.rlwrap '<Current Tool Path based on the Server Environment> \!*'
alias mysh.wmctrl '<Current Tool Path based on the Server Environment>'
alias mysh.xterm '<Current Tool Path based on the Server Environment>'
alias mysh.meld '<Current Tool Path based on the Server Environment>'
Auto completion
We can put git auto-completion or other than complete if we want. Also a lot of internal utilities and tools which does not have native auto-completion.
Share the settings
This file is a file that could be used or copied by others, so it is better to make some versions, like share_1.0.0.cshrc
and link the latest to share.cshrc
.
Style the stdout
The style is mainly about the background, color code, font size, font family, etc.
These settings go to style.cshrc
. And we can even put some settings together and give a name like “theme”.
Behaviour setting
This sets some environment, or tool settings, like initialize git mode, name, email, etc. And others like global variables GREP options, etc.
Csh function-like utility
Cshell does not have a function, but we can use “source” to let the command behave like a function. Here is the way.
- Code a cshell script which can accept arguments
- Create an alias and define the program name
setenv __MYSH_ROOT "~/.mysh"
alias myecho "source $__MYSH_ROOT/cshsub/myecho.csh --program myecho \!*"
Now in your other cshell or interactive shell, we can use myecho like an executable script instead of making myecho.csh executable and source will apply the setting in the current shell, but the executable program may execute the function in a standalone shell.
myecho -pcolor "blue" -prefix "MY-TEST" -color yellow "This is my message."
Here is the output: MY-TEST: This is my message.
For more detail, check another post talking about making csh function-like utility.