:ok_hand: Instant terminal aliases
:ok_hand: Create permanent terminal aliases instantly
β οΈUnder construction, beware of breaking changes β οΈ
Save a new alias forever
$ pluc <alias> <command>
Leave out "command
" and pluc will use your last command from shell history.
$ pluc <alias>
Here's what this could look like:
$ pluc serve "python -m SimpleHTTPServer"
π Aliased "serve" to "python -m SimpleHTTPServer" π
or
$ pluc ya "yarn add"
π Aliased "ya" to "yarn add" π
$ ya react #Your new alias is instantly usable
$ npm install --global pluc
Now source the pluc output file in your shell. Paste this in your bash profile (~/.bashrc, ~/.zshrc, ~/.bash_profile, , or ~/.profile).
source "$(pluc-cli --destinationPath)" #source pluc aliases on shell startup
function pluc() { #call pluc-cli and source new alias immediatly
pluc-cli "$@"
source "$(pluc-cli --destinationPath)"
}
Should you ignore the above bash code, you'd need to manually resource the pluc shell file per session and after adding a new alias.
$ pluc --sourcePath
# Should output a json filepath, not an error.
Your bash aliases are generated from that JSON object. You don't need to pay attention to that in most cases. That's covered in depth in the "About" section below.
Imagine you ssh to this machine often:
$ ssh [email protected]
# ssh: Successfully ssh'd to example.org!
But truly, you do that most days. Why should you type it out?
$ pluc sshme
# π Aliased "sshme" to "ssh [email protected]" π
$ sshme
# ssh: Successfully ssh'd to example.org!
Not only is the alias sshme
instantly available, it's forever available in any new sessions. The alternative is to save an alias
in your bash profile. It's not only time consuming to open and edit, but you won't be able to use that alias until you source
it.
Or let's say you do web development and need a web server often:
$ pluc serve "python -m SimpleHTTPServer"
# π Aliased "serve" to "python -m SimpleHTTPServer" π
$ serve
# Serving HTTP on 0.0.0.0 port 8000 ...
Although it's always recommended that you quote the command for safety with bash argument splitting, your second argument can contain spaces! Parsing of this is done on your behalf by pluc
. If your command contains flags though, you must quote it, which is why it's not a good habit.
If you want to see the full list of commands:
$ pluc --help
pluc
uses a single JSON object to store aliases. Since JSON is already key-value based, it's a perfect data format. To manually edit the JSON source file (you absolutely will eventually) enter
$ $EDITOR $(pluc --sourcePath)
After any new alias is added to pluc
, the render
function is called which builds a shell file. The shell output is what you source
'd at the very beginning. To see it right now, enter
$ $EDITOR $(pluc --destinationPath)
:warning: Do not edit the output shell file, it gets deleted on re-render (often) :warning:
Are you saving important aliases or a large amount of them? If so, back these up.
First find the path your config file is saved in:
$ pluc --sourcePath
# /Users/dawsonbotsford/Library/Preferences/pluc-nodejs/config.json
This file needs to be moved into Dropbox and symlinked back to the original location
mv /Users/dawsonbotsford/Library/Preferences/pluc-nodejs/config.json ~/Dropbox/
ln -s ~/Dropbox/config.json /Users/dawsonbotsford/Library/Preferences/pluc-nodejs/config.json
Alternatively, use git to manually version control.
$ pluc --sourcePath
# /Users/dawsonbotsford/Library/Preferences/pluc-nodejs/config.json
$ cd /Users/dawsonbotsford/Library/Preferences/pluc-nodejs
$ git init
# add remote, and push!
Why not use the source
command in my terminal?
source
is only available within your current shell. As soon as you start a new session, your alias is gone.How can I edit my aliases?
$ $EDITOR $(pluc --sourcePath)
Why store the data as a JSON object?
vimrc
, sublime snippets, etc.) which is key-value based can be generated using pluc
.What's one of these "pluc JSON objects" actually look like?
{
"gi": "git init",
"ga": "git add"
}
pluc <alias>
alone is not accurate.
pluc
will not create valid aliases on Windows. Windows does not save terminal history.
pluc
will not work with fish
shell. It likely will not work for shells beyond bash or zsh. This is because of the parse
function in @dawsbot/shell-history
package. PR's welcome.
MIT Β© Dawson Botsford