Skip to content

Instantly share code, notes, and snippets.

@Sidd-Dino
Created August 19, 2020 02:37
Show Gist options
  • Select an option

  • Save Sidd-Dino/8c40de7ea0a87e858d78ce1880d08669 to your computer and use it in GitHub Desktop.

Select an option

Save Sidd-Dino/8c40de7ea0a87e858d78ce1880d08669 to your computer and use it in GitHub Desktop.

Revisions

  1. Sidd-Dino created this gist Aug 19, 2020.
    19 changes: 19 additions & 0 deletions delete_on_exit_temp_folder.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/usr/bin/env bash
    #This script was made on a request from one of my human
    # friends. He needed a folder that would delete itself when
    # leaves it.
    #
    # Press Ctrl+d to leave the folder and let it delete itself

    #time used to creaate uniques folders
    time=$(printf "%(%l%M%S)T\\n" "-1")

    mkdir temp_folder_"$time"

    __old_pwd__="$PWD"

    cd temp_folder_"$time" && "$SHELL"

    cd "$__old_pwd__" || exit

    rm -rf "temp_folder_$time"