mirror of
https://github.com/mintycube/fast-files.git
synced 2024-10-22 14:05:52 +02:00
first commit
This commit is contained in:
commit
f6561b5721
135
README.md
Normal file
135
README.md
Normal file
@ -0,0 +1,135 @@
|
||||
# Fast Files (ff)
|
||||
|
||||
## Description
|
||||
|
||||
ff is a 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](https://github.com/eza-community/eza) (optional)
|
||||
- [lsd](https://github.com/lsd-rs/lsd) (optional)
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
ff [path file or folder]
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Single file
|
||||
|
||||
```bash
|
||||
ff file
|
||||
```
|
||||
|
||||
```
|
||||
file
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Single directory
|
||||
|
||||
```bash
|
||||
ff dir/
|
||||
```
|
||||
|
||||
```
|
||||
dir
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Multiple files
|
||||
|
||||
```bash
|
||||
ff file1 file2 file3
|
||||
```
|
||||
|
||||
```
|
||||
file1
|
||||
file2
|
||||
file3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Multiple directories
|
||||
|
||||
```bash
|
||||
ff dir1/ dir2/ dir3/
|
||||
```
|
||||
|
||||
```
|
||||
dir1
|
||||
dir2
|
||||
dir3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### File in a directory
|
||||
|
||||
```bash
|
||||
ff dir/file
|
||||
```
|
||||
|
||||
```
|
||||
dir
|
||||
└── file
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Directory in a directory
|
||||
|
||||
```bash
|
||||
ff dir1/dir2/
|
||||
```
|
||||
|
||||
```
|
||||
dir1
|
||||
└── dir2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Multiple files in multiple directories
|
||||
|
||||
```bash
|
||||
ff dir1/dir2/file1 dir3/file2
|
||||
```
|
||||
|
||||
```
|
||||
dir1
|
||||
└── dir2
|
||||
└── file1
|
||||
dir3
|
||||
└── file2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### If your shell supprts 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
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Related Projects
|
||||
|
||||
[Advanced New File](https://github.com/tanrax/terminal-AdvancedNewFile)
|
104
ff
Executable file
104
ff
Executable file
@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# █▀▀ ▄▀█ █▀ ▀█▀ █▀▀ █ █ █▀▀ █▀
|
||||
# █▀ █▀█ ▄█ █ █▀ █ █▄▄ ██▄ ▄█
|
||||
#
|
||||
# Usage: ff [path file or folder]
|
||||
#
|
||||
# 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:
|
||||
# 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
|
||||
# - If your shell supprts 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
|
||||
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" == */ ]]; 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
|
||||
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
|
||||
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
|
||||
- If your shell supprts 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 executing directly from the command line.
|
||||
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
||||
listObjects "$@"
|
||||
fi
|
Loading…
Reference in New Issue
Block a user