Skip to content

Instantly share code, notes, and snippets.

@DanBurkhardt
Last active March 29, 2023 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanBurkhardt/89c66d4e5ccf9b767fde3e69f691b3a5 to your computer and use it in GitHub Desktop.
Save DanBurkhardt/89c66d4e5ccf9b767fde3e69f691b3a5 to your computer and use it in GitHub Desktop.
Whomst: an alias for those whomst.
#!/bin/bash
# Licensed under MIT, see license below.
cat << "EOF"
###########################################
# _ _ _ _ #
# | | | | | | | #
# | | | | |__ ___ _ __ ___ ___| |_ #
# | |/\| | '_ \ / _ \| '_ ` _ \/ __| __| #
# \ /\ / | | | (_) | | | | | \__ \ |_ #
# \/ \/|_| |_|\___/|_| |_| |_|___/\__| #
# #
###########################################
## An alias for those.. whomst. ##
EOF
runMsg="try opening a new terminal, and running \"whomst\"√√√√"
# handle already installed
alreadyInstalled() {
printf "whomst is already installed √√√\n\n"
printf "$runMsg\n\n"
}
# add it if not installed
notInstalled() {
printf "adding whomst to the default $user_default_shell profile √√√\n\n"
echo "alias whomst=\"whoami\"" | tee -a $shell_profile
printf "finished setup √√√√\n\n"
printf "$runMsg√\n\n"
}
# check if it is installed
checkIfInstalled() {
printf "checking existing setup √√\n\n"
if grep -q "whomst" $shell_profile; then
alreadyInstalled;
else
echo "false";
notInstalled;
fi
}
# vars
user_default_shell="$(grep $USER </etc/passwd | cut -f 7 -d ":" | cut -f 4 -d "/")"
w_alias="alias whomst=\"whoami\""
shell_profile=""
# run the installed setup & checks
runSetup() {
printf "\n\nrunning whomst setup √\n\n"
# setup the proper path to shell .profile
if [ "$user_default_shell" == "zsh" ]; then
shell_profile=~/.zshrc;
elif [ "$user_default_shell" == "bash" ]; then
shell_profile=~/.bash_profile
fi
# perform checks
checkIfInstalled
}
# LFG
runSetup
# Whomst
# An alias for those .. whomst.
## What is this?
# Whomst is a novelty/overkill script that simply allows you to use the command `whomst` any time you'd normally us `whoami`.
# Whomst it is just a silly alias of `whoami` that is added to your shell profile so you can use it in the terminal.
## Install
# Method 1: download, make executable, run.
#
# Method2: download and install with bash
#
# /usr/bin/bash -c \
# "$(curl -fsSl https://gist.githubusercontent.com/DanBurkhardt/89c66d4e5ccf9b767fde3e69f691b3a5/raw)"
#
## Use
#
# After installation:
# - launch terminal
# - run `whomst`
# - you will see your user name printed to the terminal.
# You can use `whomst` anywhwere you'd normally us `whoami`, because it is just a silly alias of `whoami`.
### Background / Why?
# I got the idea to write this because, firstly, I genuinely laugh out loud typing `whomst` instead of `whoami` into the cli.
#
# But then it became a broader exercise, moving from local alias, towards something that would let me practice some of the more common installer / scripting tasks, such as:
#
# - Reliable detection of the current user's default login shell for both macOS and Linux CLI environments
# - Handling of multiple types of default shells (Bash & Zsh)
# - Performing basic conditional checks, such as seeing if the alias is already installed
# - This is where the unique title comes in, being unlikely that a user's shell profile has another alias with the same name (though it does not guard for that explicitly //todo?)
# - Thinking through some considerations when aiming to distribute an installer for multiple platforms
# - Printing banners that are directly embedded in shell scripts
# - using funny / novel formatting in log messages
# Enjoy!
# License: MIT
# Copyright 2021, Gigabitelabs
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment