-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added first version of the Cinnamon action "Backup this file": * This action will create a backup file by copying and appending a .bkp suffix to the new file.
- Loading branch information
Showing
10 changed files
with
159 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### 0.0.1 | ||
|
||
* Initial release |
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,23 @@ | ||
BACKUP THIS FILE | ||
================ | ||
|
||
Create a backup of the selected file by copying it and appending the suffix .bkp. | ||
|
||
DESCRIPTION | ||
----------- | ||
|
||
By selecting a file and clicking "Backup this File," a new file will be created following the pattern `<filename>.bkp`. | ||
|
||
If a `.bkp` file already exists for the selected file, the new one will be generated with an index at the end, like `.bkp2`. | ||
|
||
If a `.bkp2` file already exists, a `.bkp3` will be created, and so on. | ||
|
||
This is useful for backing up config files during tests. | ||
|
||
DEPENDENCIES | ||
------------ | ||
|
||
The following programs must be installed and available: | ||
|
||
* `gettext` to get the correct translation to the action | ||
* `bash` to execute the commands |
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,10 @@ | ||
[Nemo Action] | ||
_Name=Backup this file | ||
_Comment=Backup the selected file by creating a copy and appending the suffix .bkp | ||
Exec=<backup-this-file@h3nr1ke/backup-this-file.sh "%F"> | ||
Conditions=exec <backup-this-file@h3nr1ke/check.sh "%F">; | ||
Icon-Name=edit-copy-symbolic | ||
Selection=notnone | ||
Extensions=any; | ||
Dependencies=gettext;bash; | ||
Separator=" " |
40 changes: 40 additions & 0 deletions
40
backup-this-file@h3nr1ke/files/backup-this-file@h3nr1ke/backup-this-file.sh
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,40 @@ | ||
#!/bin/bash | ||
|
||
FILENAME="$1" | ||
BACKUP_COUNT_SUFFIX="" | ||
BACKUP_FILE_NAME=$FILENAME.bkp | ||
GREP_REGEX='+[0-9]{0,}+$' | ||
|
||
# since we validated if the file exists in the check process | ||
# now we need to check if a backup file already exists | ||
BAKUP_FILE_EXISTS=$(ls $BACKUP_FILE_NAME* -v 2>/dev/null) | ||
|
||
# if this variable is not empty, so backup files exists in the folder | ||
if [[ ! -z "$BAKUP_FILE_EXISTS" ]]; then | ||
|
||
|
||
TOTALBACKUPFILES=$(ls $BACKUP_FILE_NAME* -v | wc -l) | ||
|
||
# if more than one backup exists, we need to read the last number and | ||
# increase it by 1 to generate the new backup file | ||
if (($TOTALBACKUPFILES > 0 )); then | ||
|
||
# get the last file but only the ones created with a number in the end | ||
LAST_FILE_COUNT=$(ls $BACKUP_FILE_NAME* -v | grep -oE $GREP_REGEX | tail -n 1) | ||
|
||
## verify the next one to be created | ||
if [[ -z "$LAST_FILE_COUNT" ]]; then | ||
# there is a single backup file, so the next one will be 2 | ||
BACKUP_COUNT_SUFFIX=2 | ||
else | ||
# there are various bkp files, lets check and create a new one based in the last one | ||
((LAST_FILE_COUNT++)) | ||
BACKUP_COUNT_SUFFIX=$LAST_FILE_COUNT | ||
fi | ||
fi | ||
fi | ||
|
||
# lets create the backup file | ||
cp $FILENAME $BACKUP_FILE_NAME$BACKUP_COUNT_SUFFIX | ||
|
||
exit 0 |
12 changes: 12 additions & 0 deletions
12
backup-this-file@h3nr1ke/files/backup-this-file@h3nr1ke/check.sh
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,12 @@ | ||
#!/bin/bash | ||
|
||
FILEPATH=$1 | ||
FOLDER="$(dirname "$FILEPATH")" | ||
|
||
|
||
# is this not a file or we canot write in the folder ? | ||
if [[ ! -f $FILEPATH ]] || [[ ! -w "$FOLDER" ]]; then | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions
7
backup-this-file@h3nr1ke/files/backup-this-file@h3nr1ke/metadata.json
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,7 @@ | ||
{ | ||
"description": "Create a backup of the selected file by copying it and appending the suffix .bkp.", | ||
"uuid": "backup-this-file@h3nr1ke", | ||
"name": "Backup this file", | ||
"author": "h3nr1ke", | ||
"version": "0.0.1" | ||
} |
29 changes: 29 additions & 0 deletions
29
backup-this-file@h3nr1ke/files/backup-this-file@h3nr1ke/po/[email protected]
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,29 @@ | ||
# SOME DESCRIPTIVE TITLE. | ||
# This file is put in the public domain. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: backup-this-file@h3nr1ke 0.0.1\n" | ||
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/" | ||
"issues\n" | ||
"POT-Creation-Date: 2024-05-23 16:53-0600\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
"Language: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
|
||
#. metadata.json->description | ||
#. [email protected]_action.in->Comment | ||
msgid "" | ||
"Create a backup of the selected file by copying it and appending the suffix .bkp." | ||
msgstr "" | ||
|
||
#. metadata.json->name | ||
#. [email protected]_action.in->Name | ||
msgid "Backup this file" | ||
msgstr "" |
32 changes: 32 additions & 0 deletions
32
backup-this-file@h3nr1ke/files/backup-this-file@h3nr1ke/po/pt_BR.po
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,32 @@ | ||
# SOME DESCRIPTIVE TITLE. | ||
# This file is put in the public domain. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: backup-this-file@h3nr1ke 0.0.1\n" | ||
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/" | ||
"issues\n" | ||
"POT-Creation-Date: 2024-05-23 16:53-0600\n" | ||
"PO-Revision-Date: 2024-05-23 17:01-0600\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"Language: pt_BR\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"X-Generator: Poedit 3.4.4\n" | ||
|
||
#. metadata.json->description | ||
#. [email protected]_action.in->Comment | ||
msgid "" | ||
"Create a backup of the selected file by copying it and appending the suffix ." | ||
"bkp." | ||
msgstr "" | ||
"Crie um backup do arquivo selecionado copiando-o e adicionando o sufixo .bkp." | ||
|
||
#. metadata.json->name | ||
#. [email protected]_action.in->Name | ||
msgid "Backup this file" | ||
msgstr "Criar um backup deste arquivo" |
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,3 @@ | ||
{ | ||
"author": "h3nr1ke" | ||
} |