Add cardboard function
This commit is contained in:
parent
c0e490776e
commit
910b70849b
2 changed files with 94 additions and 0 deletions
93
alex/fish/functions/cardboard.fish
Normal file
93
alex/fish/functions/cardboard.fish
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
function cardboard
|
||||||
|
set -l mnt_option
|
||||||
|
set -l display_help
|
||||||
|
|
||||||
|
for arg in $argv
|
||||||
|
switch $arg
|
||||||
|
case '-h' '--help'
|
||||||
|
set display_help 1
|
||||||
|
case '*'
|
||||||
|
set mnt_option $arg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if test "$display_help"
|
||||||
|
echo "Usage: cardboard [directory] [-h | --help]"
|
||||||
|
echo ""
|
||||||
|
echo "Mounts a tmpfs with read-write permissions for the user calling it and no permissions for anyone else."
|
||||||
|
echo "Automatically changes the current working directory to the mounted tmpfs directory."
|
||||||
|
echo ""
|
||||||
|
echo "Options:"
|
||||||
|
echo " -h, --help Show this help message and exit"
|
||||||
|
echo ""
|
||||||
|
echo "To unmount the tmpfs and return to your home directory, run 'uncardboard'."
|
||||||
|
echo "To securely delete all files inside the mount directory, run 'shred-cardboard'."
|
||||||
|
echo "To list the files that would be shredded without actually deleting them, run 'shred-cardboard-dry-run'."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
set user (whoami)
|
||||||
|
|
||||||
|
if test -n "$mnt_option"
|
||||||
|
set mnt_dir $mnt_option
|
||||||
|
else
|
||||||
|
set mnt_dir "/home/$user/mnt/ramfs"
|
||||||
|
end
|
||||||
|
|
||||||
|
set -gx CARDBOARD_MOUNT_DIR $mnt_dir
|
||||||
|
|
||||||
|
if mount | grep -q " $mnt_dir "
|
||||||
|
echo "A tmpfs is already mounted at $mnt_dir."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
mkdir -p $mnt_dir
|
||||||
|
|
||||||
|
# Mount the tmpfs so its root directory is owned by the current user
|
||||||
|
sudo mount -t tmpfs -o size=512M,mode=700,uid=(id -u),gid=(id -g) tmpfs $mnt_dir
|
||||||
|
|
||||||
|
cd $mnt_dir
|
||||||
|
|
||||||
|
function uncardboard
|
||||||
|
if test -z "$CARDBOARD_MOUNT_DIR"
|
||||||
|
echo "No cardboard mount directory found."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if test "$PWD" = "$CARDBOARD_MOUNT_DIR"
|
||||||
|
cd /home/$user
|
||||||
|
end
|
||||||
|
|
||||||
|
sudo umount $CARDBOARD_MOUNT_DIR
|
||||||
|
end
|
||||||
|
|
||||||
|
function shred-cardboard
|
||||||
|
if test -z "$CARDBOARD_MOUNT_DIR"
|
||||||
|
echo "No cardboard mount directory found."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if test "$PWD" = "$CARDBOARD_MOUNT_DIR"
|
||||||
|
echo "Please change to a different directory before running shred-cardboard."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Shredding all files in $CARDBOARD_MOUNT_DIR..."
|
||||||
|
find $CARDBOARD_MOUNT_DIR -type f -exec shred -u -v {} \;
|
||||||
|
echo "All files in $CARDBOARD_MOUNT_DIR have been securely deleted."
|
||||||
|
end
|
||||||
|
|
||||||
|
function shred-cardboard-dry-run
|
||||||
|
if test -z "$CARDBOARD_MOUNT_DIR"
|
||||||
|
echo "No cardboard mount directory found."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Files that would be shredded in $CARDBOARD_MOUNT_DIR:"
|
||||||
|
find $CARDBOARD_MOUNT_DIR -type f
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "To unmount the tmpfs and return to your home directory, run 'uncardboard'."
|
||||||
|
echo "To securely delete all files inside the mount directory, run 'shred-cardboard'."
|
||||||
|
echo "To list the files that would be shredded without actually deleting them, run 'shred-cardboard-dry-run'."
|
||||||
|
end
|
||||||
|
|
@ -174,6 +174,7 @@
|
||||||
programs.fish = {
|
programs.fish = {
|
||||||
enable = true;
|
enable = true;
|
||||||
interactiveShellInit = ''
|
interactiveShellInit = ''
|
||||||
|
source ~/.config/fish/functions/cardboard.fish
|
||||||
source ~/.config/fish/functions/bangbang.fish
|
source ~/.config/fish/functions/bangbang.fish
|
||||||
source ~/.config/fish/functions/borg-h.fish
|
source ~/.config/fish/functions/borg-h.fish
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue