Tired of manually wrestling with shell configuration files every time you need a quick alias? gst is your speedy shortcut to shell efficiency! This handy command-line utility lets you swiftly add, update, or temporarily set shell aliases for Bash, Zsh, and Fish, all without the usual hassle of editing config files. Say goodbye to friction and hello to fluent alias management!
We've all been there: you want to create a simple shortcut for a long command. This usually means opening ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish, carefully finding the right spot, typing alias mycmd='some long command', saving, and then remembering to source the file. It's a cumbersome process for what should be a quick task, especially for those everyday, throwaway aliases.
gst slashes through that tedious workflow! It removes the friction from alias management by offering a streamlined, command-line-driven approach. Whether you need an alias for the next five minutes or the next five years, gst makes it fast and effortless.
gst empowers you with a range of features designed to simplify your shell experience:
- Rapid Alias Management: Quickly add, update, or temporarily set shell aliases directly from your terminal.
- Broad Shell Compatibility: Works seamlessly with Bash, Zsh, and Fish shells.
- Effortless Temporary Aliases: Create aliases for your current session without touching any configuration files.
- Simplified Permanent Aliases: Streamlines the process of making your favorite shortcuts permanent.
- Intuitive Syntax: Designed for ease of use and quick adoption.
- Get the script:
- The
gstscript is namedgst.shand is located in this repository. You will need to copy its content or download it.
- The
- Make it executable:
chmod +x gst.sh
- Move it to a directory in your PATH:
- A common location is
~/.local/bin. If this directory doesn't exist, create it first:mkdir -p ~/.local/bin - Then, move the script:
mv gst.sh ~/.local/bin/gst
- A common location is
- Verify PATH:
- Ensure
~/.local/binis included in your shell'sPATH. You can check this by running:echo $PATH
- If it's not there, add it to your shell's configuration file (e.g.,
~/.bashrc,~/.zshrc, or~/.config/fish/config.fish). For example, you could add the following line (for Bash/Zsh):For Fish shell, the syntax is different:export PATH="$HOME/.local/bin:$PATH"
set -gx PATH "$HOME/.local/bin" $PATH
- Remember to source your configuration file (e.g.,
source ~/.bashrc) or open a new terminal session for the changes to take effect.
- Ensure
To make gst even easier to use, set up the gsta wrapper function in your shell's configuration file. This function allows gst to directly modify your current shell session's aliases, making the experience even smoother.
Add the following function to your ~/.bashrc file:
gsta() {
if [ "$#" -eq 0 ]; then gst; return; fi
local output; output=$(gst "$@")
if [ -n "$output" ]; then eval "$output"; fi
}After adding, reload your configuration by running:
source ~/.bashrcOr, open a new terminal session.
Add the following function to your ~/.zshrc file:
gsta() {
if [ "$#" -eq 0 ]; then gst; return; fi
local output; output=$(gst "$@")
if [ -n "$output" ]; then eval "$output"; fi
}After adding, reload your configuration by running:
source ~/.zshrcOr, open a new terminal session.
Add the following function to your ~/.config/fish/config.fish file:
function gsta
if count $argv > /dev/null
gst $argv | source
else
gst
end
endAfter adding, reload your configuration by running:
source ~/.config/fish/config.fishOr, open a new terminal session.
Once gst is installed and the gsta wrapper function (from the Setup section) is configured in your shell, you can manage aliases as follows.
Note: Behavior for updating and removing aliases should be verified with the
gst.shscript's functionality, as the script's exact mechanisms for these actions are not detailed here. It's assumed thatgstwill overwrite an existing alias if you define it again.
Permanent aliases are saved to your shell's configuration file and will be available in future sessions.
-
Simple alias: Create an alias
lslfor the commandls -la.gsta lsl "ls -la" -
Alias with multiple options and arguments: Create
mygitfor a complex Git log command.gsta mygit "git log --oneline --decorate --all --graph" -
Alias for a sequence of commands: Create
godeployto change directory and run a script. (Ensure the path/my/projectis correct for your use case).gsta godeploy "cd /my/project && ./deploy.sh"
Temporary aliases are set only for the current shell session and will be gone when the session ends. Use the -t flag.
-
Simple temporary alias: Create a temporary alias
ll.gsta -t ll "ls -lh" -
Temporary alias for a sequence of commands: Create
proddbfor an SSH tunnel, only for the current session.gsta -t proddb "ssh user@prod-server -p 2222 -L 5432:localhost:5432"
To view aliases:
- Using
gstdirectly (if it supports listing):gst
- Using the
gstawrapper (if configured to callgstwith no arguments):gsta
- Using your shell's built-in command (shows all aliases):
For Bash/Zsh:
For Fish:
aliasfunctions -t # or simply `functions` to see all functions including aliases
Note:
gstmight only list aliases it directly manages. Using your shell's built-in command provides a comprehensive list.
To update an existing alias, it's generally assumed you can run the gsta command again with the same alias name and the new command string.
- Updating an existing permanent alias: If
lslwasls -la, to change it tols -alh:gsta lsl "ls -alh"
Note: This assumes
gstoverwrites the existing alias. Please verify this behavior with thegst.shscript. If it doesn't overwrite, you might need to remove the old alias manually first from your shell configuration file.
-
Temporary Aliases: Temporary aliases are automatically removed when your current shell session ends. No command is needed.
-
Permanent Aliases: The
gstscript's specific mechanism for removing permanent aliases is not detailed in this README.- Check the script: Look for a removal option in the script's help output (e.g.,
gst --help) or its source code (e.g.,gsta -r alias_nameorgst --remove alias_name). - Manual Removal: If
gstdoes not provide a direct removal command, you will need to manually edit your shell's configuration file (~/.bashrc,~/.zshrc, or~/.config/fish/config.fish). Delete the line defining the alias (e.g.,alias lsl="ls -alh"), and then source the file or open a new terminal.
- Check the script: Look for a removal option in the script's help output (e.g.,
Note: The exact method for removing permanent aliases managed by
gstshould be verified by checking thegst.shscript's functionality.
Contributions are welcome! Please feel free to submit pull requests or open issues. We're excited to see how the community can help make gst even better!
