mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
51 lines
729 B
Bash
Executable File
51 lines
729 B
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Create a directory and cd into it
|
|
# Usage: mkcd <dir>
|
|
|
|
set -euo pipefail
|
|
|
|
# Set verbosity with VERBOSE=1
|
|
VERBOSE="${VERBOSE:-0}"
|
|
|
|
# Function to print usage information
|
|
usage()
|
|
{
|
|
echo "Usage: $0 <dir>"
|
|
exit 1
|
|
}
|
|
|
|
# Function to print messages if VERBOSE is enabled
|
|
# $1 - message (string)
|
|
msg()
|
|
{
|
|
[[ "$VERBOSE" -eq 1 ]] && echo "$1"
|
|
}
|
|
|
|
# Function to create a directory and cd into it
|
|
# $1 - directory to create and cd into (string)
|
|
mkcd()
|
|
{
|
|
local dir=$1
|
|
|
|
mkdir -p "$dir" && msg "Directory $dir created"
|
|
|
|
cd "$dir" || {
|
|
msg "Failed to cd into $dir"
|
|
exit 1
|
|
}
|
|
msg "Changed directory to $dir"
|
|
}
|
|
|
|
# Main function
|
|
main()
|
|
{
|
|
if [ "$#" -ne 1 ]; then
|
|
usage
|
|
fi
|
|
|
|
mkcd "$1"
|
|
}
|
|
|
|
main "$@"
|