-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bc0275
commit 5ddfed3
Showing
6 changed files
with
96 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,7 @@ | |
.history | ||
.ionide | ||
|
||
# Test files | ||
tmp | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# Init constants | ||
BACKUP_DIR_NAME=".rbsh" | ||
META_FILE_NAME=".rbsh_meta" | ||
BACKUP_DIR_PATH="$HOME/$BACKUP_DIR_NAME" | ||
META_FILE_PATH="$HOME/$META_FILE_NAME" | ||
|
||
# Remove source objects (files, directories, etc.) | ||
remove() { | ||
# $1 is source object | ||
|
||
this_time=$(($(date +%s%N)/1000000)) | ||
obj_backup_dir_name="$(echo $this_time)_$(basename $1)" | ||
obj_backup_dir_path="$BACKUP_DIR_PATH/$obj_backup_dir_name/" | ||
source_obj=$1 | ||
|
||
if [ -d $1 ]; then | ||
source_obj="$source_obj/" | ||
fi | ||
|
||
mkdir "$obj_backup_dir_path" && \ | ||
mv "$source_obj" "$obj_backup_dir_path" && \ | ||
add_meta $obj_backup_dir_name | ||
} | ||
|
||
clear() {} | ||
|
||
add_meta() { | ||
echo "$1" >> "$META_FILE_PATH" | ||
} | ||
|
||
remove $1 | ||
# CLI options | ||
HELP_OPTION_LONG="--help" | ||
HELP_OPTION_SHORT="-h" | ||
LIST_ARGUMENT="list" | ||
|
||
# Load core functions | ||
source ./source/core.sh | ||
|
||
# Check options and arguments | ||
while [ "$#" -gt 0 ]; do | ||
case "${1^^}" in | ||
"${LIST_ARGUMENT^^}") | ||
list_objects | ||
shift | ||
;; | ||
"${HELP_OPTION_LONG^^}" | "${HELP_OPTION_SHORT^^}") | ||
show_help | ||
shift | ||
;; | ||
*) | ||
shift | ||
;; | ||
esac | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
TMP_DIR_PATH="./tmp" | ||
|
||
rm -rf $TMP_DIR_PATH | ||
|
||
mkdir -p $TMP_DIR_PATH/test1/test1_sub1 | ||
touch $TMP_DIR_PATH/test1/apple.js | ||
touch $TMP_DIR_PATH/test1/test1_sub1/test1_sub1_apple.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# Remove source objects (files, directories, etc.) | ||
remove() { | ||
# $1 is source object | ||
|
||
this_time=$(($(date +%s%N)/1000000)) | ||
obj_backup_dir_name="$(echo $this_time)_$(basename $1)" | ||
obj_backup_dir_path="$BACKUP_DIR_PATH/$obj_backup_dir_name/" | ||
source_obj=$1 | ||
|
||
if [ -d $1 ]; then | ||
source_obj="$source_obj/" | ||
fi | ||
|
||
mkdir "$obj_backup_dir_path" && \ | ||
mv "$source_obj" "$obj_backup_dir_path" && \ | ||
add_meta $obj_backup_dir_name $(realpath $1) | ||
} | ||
|
||
# Add metadata to rbsh meta file | ||
add_meta() { | ||
# $1 is backup file path | ||
# $2 is source absolute path | ||
|
||
echo "$1, $2" >> "$META_FILE_PATH" | ||
} | ||
|
||
# List all removed objects | ||
list_objects() { | ||
ls -la $BACKUP_DIR_PATH | ||
} | ||
|
||
# Show cli help | ||
show_help() { | ||
rm --help | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Describe 'sample' | ||
Describe 'implemented by shell function' | ||
Include ./scripts/file_mock.sh | ||
|
||
It 'performs addition' | ||
End | ||
End | ||
End |