Last active
May 7, 2024 15:47
-
-
Save rrcobb/1130af0d597845ad89e9830cd4a3ea42 to your computer and use it in GitHub Desktop.
add_alias bash function: `add_alias lsa ls -a`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage add_alias [name] [command] | |
# Example: add_alias today date +%Y-%m-%d | |
# creates the alias today, which executes "date +%Y-%m-%d" | |
# make sure to add a line "source ~/.sh_aliases" to your config | |
function add_alias () | |
{ | |
local cmd=$1; | |
shift; | |
local rest="$@"; | |
echo "alias $cmd=\"$rest\"" >> ~/.sh_aliases; | |
source ~/.sh_aliases | |
} | |
# Usage exec_file [file] | |
# Runs a file with the appropriate app based on the file extension | |
function exec_file() | |
{ | |
local file=$1; | |
filename=$(basename $file) | |
extension="${filename##*.}" | |
if [ "$extension" = "py" ]; then | |
python "$file" | |
elif [ "$extension" = "js" ]; then | |
node "$file" | |
elif [ "$extension" = "rb" ]; then | |
ruby "$file" | |
else | |
echo "Unsupported file extension: $extension for file $filename" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment