mirror of
https://github.com/mintycube/fast-files.git
synced 2024-10-22 14:05:52 +02:00
Remove -v option and add ffv
Removes the -v argument and add script for verbose functionality
This commit is contained in:
parent
ce8a464a5e
commit
00cf53931f
66
README.md
66
README.md
@ -15,7 +15,6 @@ ff is a bash script which is a combination of 'mkdir' and 'touch'. It can create
|
||||
```bash
|
||||
ff [path file or folder]
|
||||
--help : prints usage info
|
||||
-v : prints created files
|
||||
```
|
||||
|
||||
## Examples
|
||||
@ -27,12 +26,9 @@ ff file
|
||||
```
|
||||
|
||||
```
|
||||
file
|
||||
|
||||
file
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Single directory
|
||||
|
||||
```bash
|
||||
@ -40,11 +36,9 @@ ff dir/
|
||||
```
|
||||
|
||||
```
|
||||
dir
|
||||
dir
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Multiple files
|
||||
|
||||
```bash
|
||||
@ -52,13 +46,11 @@ ff file1 file2 file3
|
||||
```
|
||||
|
||||
```
|
||||
file1
|
||||
file2
|
||||
file3
|
||||
file1
|
||||
file2
|
||||
file3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Multiple directories
|
||||
|
||||
```bash
|
||||
@ -66,13 +58,11 @@ ff dir1/ dir2/ dir3/
|
||||
```
|
||||
|
||||
```
|
||||
dir1
|
||||
dir2
|
||||
dir3
|
||||
dir1
|
||||
dir2
|
||||
dir3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### File in a directory
|
||||
|
||||
```bash
|
||||
@ -80,12 +70,10 @@ ff dir/file
|
||||
```
|
||||
|
||||
```
|
||||
dir
|
||||
└── file
|
||||
dir
|
||||
└── file
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Directory in a directory
|
||||
|
||||
```bash
|
||||
@ -93,12 +81,10 @@ ff dir1/dir2/
|
||||
```
|
||||
|
||||
```
|
||||
dir1
|
||||
└── dir2
|
||||
dir1
|
||||
└── dir2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Multiple files in multiple directories
|
||||
|
||||
```bash
|
||||
@ -106,32 +92,28 @@ ff dir1/dir2/file1 dir3/file2
|
||||
```
|
||||
|
||||
```
|
||||
dir1
|
||||
└── dir2
|
||||
└── file1
|
||||
dir3
|
||||
└── file2
|
||||
dir1
|
||||
└── dir2
|
||||
└── file1
|
||||
dir3
|
||||
└── file2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### If your shell supprts brace expansion e.g bash, zsh, fish
|
||||
### If your shell supports brace expansion e.g bash, zsh, fish
|
||||
|
||||
```bash
|
||||
ff dir1/{dir2/{file1,file2}.txt,dir3/file3.txt}
|
||||
```
|
||||
|
||||
```
|
||||
dir1
|
||||
├── dir2
|
||||
│ ├── file1.txt
|
||||
│ └── file2.txt
|
||||
└── dir3
|
||||
└── file3.txt
|
||||
dir1
|
||||
├── dir2
|
||||
│ ├── file1.txt
|
||||
│ └── file2.txt
|
||||
└── dir3
|
||||
└── file3.txt
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Related Projects
|
||||
|
||||
[Advanced New File](https://github.com/tanrax/terminal-AdvancedNewFile)
|
||||
|
75
ff
75
ff
@ -4,18 +4,15 @@
|
||||
# █▀▀ ▄▀█ █▀ ▀█▀ █▀▀ █ █ █▀▀ █▀
|
||||
# █▀ █▀█ ▄█ █ █▀ █ █▄▄ ██▄ ▄█
|
||||
#
|
||||
# Usage: ff [option] [path file or folder]
|
||||
# Usage: ff [path file or folder]
|
||||
#
|
||||
# --help : prints usage info
|
||||
# -v : prints created files
|
||||
# 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.
|
||||
# It can create directory structures and files simultaneously.
|
||||
#
|
||||
# Dependencies: bash
|
||||
# eza (optional)
|
||||
# lsd (optional)
|
||||
#
|
||||
# Examples: - Single file:
|
||||
# ff file
|
||||
@ -31,60 +28,18 @@
|
||||
# ff dir1/dir2/
|
||||
# - Multiple files in multiple directories
|
||||
# ff dir1/dir2/file1 dir3/file2
|
||||
# - If your shell supprts brace expansion e.g bash, zsh, fish
|
||||
# - If your shell supports brace expansion e.g bash, zsh, fish
|
||||
# ff dir1/{dir2/{file1,file2}.txt,dir3/file3.txt}
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# Gets the created files and folder names and prints them
|
||||
listObjects() {
|
||||
unique_names=()
|
||||
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" == "-v" ]]; then
|
||||
continue
|
||||
fi
|
||||
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
|
||||
}
|
||||
|
||||
# Function to create directory structures and files
|
||||
createObjects() {
|
||||
for path in "$@"; do
|
||||
if [[ "$path" == "-v" ]]; then
|
||||
continue
|
||||
fi
|
||||
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
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "No arguments provided"
|
||||
echo "Usage: ff [path file or folder]"
|
||||
echo "For more information, run: ff --help"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$1" == "--help" ]; then
|
||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
echo "Usage: ff [path file or folder]"
|
||||
echo "Examples: - Single file:
|
||||
ff file
|
||||
@ -100,14 +55,18 @@ if [ "$1" == "--help" ]; then
|
||||
ff dir1/dir2/
|
||||
- Multiple files in multiple directories
|
||||
ff dir1/dir2/file1 dir3/file2
|
||||
- If your shell supprts brace expansion e.g bash, zsh, fish
|
||||
- If your shell supports brace expansion e.g bash, zsh, fish
|
||||
ff dir1/{dir2/{file1,file2}.txt,dir3/file3.txt}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
createObjects "$@"
|
||||
|
||||
# Only print created files if "-v" (verbose) is the first argument
|
||||
if [[ "$1" == "-v" ]]; then
|
||||
listObjects "$@"
|
||||
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
|
||||
|
93
ffv
Executable file
93
ffv
Executable file
@ -0,0 +1,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
|
Loading…
Reference in New Issue
Block a user