2023-09-23 07:50:25 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# █▀▀ ▄▀█ █▀ ▀█▀ █▀▀ █ █ █▀▀ █▀
|
|
|
|
# █▀ █▀█ ▄█ █ █▀ █ █▄▄ ██▄ ▄█
|
|
|
|
#
|
2024-04-22 11:47:29 +02:00
|
|
|
# Usage: ff [path file or folder]
|
2023-09-25 14:35:54 +02:00
|
|
|
#
|
2024-04-22 11:47:29 +02:00
|
|
|
# Arguments: --help : prints usage info
|
|
|
|
# -h : prints usage info
|
2023-09-23 07:50:25 +02:00
|
|
|
#
|
|
|
|
# Description: Bash script which is a combination of 'mkdir' and 'touch'.
|
2024-04-22 11:47:29 +02:00
|
|
|
# It can create directory structures and files simultaneously.
|
2023-09-23 07:50:25 +02:00
|
|
|
#
|
|
|
|
# Dependencies: bash
|
|
|
|
#
|
|
|
|
# Examples: - Single file:
|
|
|
|
# ff file
|
|
|
|
# - Single directory:
|
|
|
|
# ff dir/
|
|
|
|
# - Multiple files:
|
|
|
|
# ff file1 file2 file3
|
|
|
|
# - Multiple directories:
|
|
|
|
# ff dir1/ dir2/ dir3/
|
|
|
|
# - File in a directory
|
|
|
|
# ff dir/file
|
|
|
|
# - Directory in a directory
|
|
|
|
# ff dir1/dir2/
|
|
|
|
# - Multiple files in multiple directories
|
|
|
|
# ff dir1/dir2/file1 dir3/file2
|
2024-04-22 11:47:29 +02:00
|
|
|
# - If your shell supports brace expansion e.g bash, zsh, fish
|
2023-09-23 07:50:25 +02:00
|
|
|
# ff dir1/{dir2/{file1,file2}.txt,dir3/file3.txt}
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
2024-04-22 11:47:29 +02:00
|
|
|
if [[ $# -eq 0 ]]; then
|
2023-09-23 07:50:25 +02:00
|
|
|
echo "No arguments provided"
|
|
|
|
echo "Usage: ff [path file or folder]"
|
|
|
|
echo "For more information, run: ff --help"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-04-22 11:47:29 +02:00
|
|
|
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
2023-09-23 07:50:25 +02:00
|
|
|
echo "Usage: ff [path file or folder]"
|
|
|
|
echo "Examples: - Single file:
|
|
|
|
ff file
|
|
|
|
- Single directory:
|
|
|
|
ff dir/
|
|
|
|
- Multiple files:
|
|
|
|
ff file1 file2 file3
|
|
|
|
- Multiple directories:
|
|
|
|
ff dir1/ dir2/ dir3/
|
|
|
|
- File in a directory
|
|
|
|
ff dir/file
|
|
|
|
- Directory in a directory
|
|
|
|
ff dir1/dir2/
|
|
|
|
- Multiple files in multiple directories
|
|
|
|
ff dir1/dir2/file1 dir3/file2
|
2024-04-22 11:47:29 +02:00
|
|
|
- If your shell supports brace expansion e.g bash, zsh, fish
|
2023-09-23 07:50:25 +02:00
|
|
|
ff dir1/{dir2/{file1,file2}.txt,dir3/file3.txt}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-04-22 11:47:29 +02:00
|
|
|
for path in "$@"; do
|
|
|
|
if [[ "$path" == */ ]]; then
|
|
|
|
mkdir -p "$path"
|
|
|
|
fi
|
|
|
|
parent_dir=$(dirname "$path")
|
|
|
|
if [[ -n "$parent_dir" ]] && [[ ! -d "$parent_dir" ]]; then
|
|
|
|
mkdir -p "$parent_dir"
|
|
|
|
fi
|
|
|
|
touch "$path"
|
|
|
|
done
|