-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffv
executable file
·93 lines (88 loc) · 3.15 KB
/
ffv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
#-----------------------------------------------------------------------------
# █▀▀ ▄▀█ █▀ ▀█▀ █▀▀ █ █ █▀▀ █▀ █░█ █▀▀ █▀█ █▄▄ █▀█ █▀ █▀▀
# █▀ █▀█ ▄█ █ █▀ █ █▄▄ ██▄ ▄█ ▀▄▀ ██▄ █▀▄ █▄█ █▄█ ▄█ ██▄
#
# Usage: ffv [path file or folder]
#
# Arguments: --help : prints usage info
# -h : prints usage info
#
# Description: Bash script which is a combination of 'mkdir' and 'touch'.
# It can create directory structures and files simultaneously
# and lists the created objects using eza, lsd, or ls.
#
# Dependencies: bash, eza (optional), lsd (optional)
#
# Examples: - Single file:
# ffv file
# - Single directory:
# ffv dir/
# - Multiple files:
# ffv file1 file2 file3
# - Multiple directories:
# ffv dir1/ dir2/ dir3/
# - File in a directory
# ffv dir/file
# - Directory in a directory
# ffv dir1/dir2/
# - Multiple files in multiple directories
# ffv dir1/dir2/file1 dir3/file2
# - If your shell supports brace expansion e.g bash, zsh, fish
# ffv dir1/{dir2/{file1,file2}.txt,dir3/file3.txt}
#-----------------------------------------------------------------------------
if [[ $# -eq 0 ]]; then
echo "No arguments provided"
echo "Usage: ffv [path file or folder]"
echo "For more information, run: ffv --help"
exit 1
fi
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
echo "Usage: ffv [path file or folder]"
echo "Examples: - Single file:
ffv file
- Single directory:
ffv dir/
- Multiple files:
ffv file1 file2 file3
- Multiple directories:
ffv dir1/ dir2/ dir3/
- File in a directory
ffv dir/file
- Directory in a directory
ffv dir1/dir2/
- Multiple files in multiple directories
ffv dir1/dir2/file1 dir3/file2
- If your shell supports brace expansion e.g bash, zsh, fish
ffv dir1/{dir2/{file1,file2}.txt,dir3/file3.txt}"
exit 0
fi
# Create directory structures and files
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
# Get the created files and folder names and print them
unique_names=()
for arg in "$@"; do
name="${arg%%/*}"
if [ -n "$name" ]; then
if [[ ! " ${unique_names[*]} " =~ $name ]]; then
unique_names+=("$name")
fi
fi
done
if command -v eza &>/dev/null; then
eza -aU --no-user --no-filesize --no-permissions --tree --icons \
--group-directories-first "${unique_names[@]}"
elif command -v lsd &>/dev/null; then
lsd -al --tree --icon=always --group-directories-first "${unique_names[@]}"
else
ls -ARl --color=always "${unique_names[@]}"
fi