Skip to content

Instantly share code, notes, and snippets.

@adde88
Last active January 17, 2024 20:14
Show Gist options
  • Save adde88/771e0283e03684005eb7b7224074f588 to your computer and use it in GitHub Desktop.
Save adde88/771e0283e03684005eb7b7224074f588 to your computer and use it in GitHub Desktop.
Kali / Debian Linux + Gnome Desktop - Right-Clicking on the Desktop to Create a New File
#!/bin/bash
# Written by: Andreas Nilsen, 09.01.2023 - <adde88@gmail.com>
# Made for Kali Linux 2024.1 / Debian 12, with Gnome Desktop Environment
#
# Installing zenity package if not already installed
if ! command -v zenity &> /dev/null; then
echo "Installing missing: 'zenity' package..."
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root to install any missing packages."
exit 1
fi
command -v apt-get &> /dev/null || { echo "This script is intended for Debian-based systems only."; exit 2; }
sudo apt-get update
sudo apt-get install -y zenity
fi
# Prompt user for script name
SCRIPT_NAME=$(zenity --entry --title="Create New Bash Script" --text="Enter New File Name:")
# Set default script name if is none provided
DEFAULT_NAME="New Script.sh"
SCRIPT_NAME="${SCRIPT_NAME:-$DEFAULT_NAME}"
# Create the file
mkdir -p "$HOME/Maler/New Files"
i=1
while [[ -e "$HOME/Maler/New Files/$SCRIPT_NAME" ]]; do
SCRIPT_NAME="${SCRIPT_NAME%.*}_$(printf "%03d" $i).${SCRIPT_NAME##*.}"
i=$((i+1))
done
touch "$HOME/Maler/New Files/$SCRIPT_NAME"
#!/bin/bash
# Written by: Andreas Nilsen, 09.01.2023 - <adde88@gmail.com>
# Made for Kali Linux 2024.1 / Debian 12, with Gnome Desktop Environment
#
# Installing zenity package if not already installed
if ! command -v zenity &> /dev/null; then
echo "Installing missing: 'zenity' package..."
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root to install any missing packages."
exit 1
fi
command -v apt-get &> /dev/null || { echo "This script is intended for Debian-based systems only."; exit 2; }
sudo apt-get update
sudo apt-get install -y zenity
fi
SCRIPT_NAME=$(zenity --entry --title="Create New Python Script" --text="Enter New File Name:")
# Set default script name if is none provided
DEFAULT_NAME="New PyScript.py"
SCRIPT_NAME="${SCRIPT_NAME:-$DEFAULT_NAME}"
# Create the file
mkdir -p "$HOME/Maler/New Files"
# If file already exists, add a number to the end of the file name
i=1
while [[ -e "$HOME/Maler/New Files/$SCRIPT_NAME" ]]; do
SCRIPT_NAME="${SCRIPT_NAME%.*}_$(printf "%03d" $i).${SCRIPT_NAME##*.}"
i=$((i+1))
done
touch "$HOME/Maler/New Files/$SCRIPT_NAME"
#!/bin/bash
# Written by: Andreas Nilsen, 09.01.2023 - <adde88@gmail.com>
# Made for Kali Linux 2024.1 / Debian 12, with Gnome Desktop Environment
#
# FILEPATH: ~/Maler/New Files/Text File
# Installing zenity package if not already installed
if ! command -v zenity &> /dev/null; then
echo "Installing missing: 'zenity' package..."
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root to install any missing packages."
exit 1
fi
command -v apt-get &> /dev/null || { echo "This script is intended for Debian-based systems only."; exit 2; }
sudo apt-get update
sudo apt-get install -y zenity
fi
FILE_NAME=$(zenity --entry --title="Create New Text File" --text="Enter New File Name:")
# Set default script name if is none provided
DEFAULT_NAME="New Text File.txt"
FILE_NAME="${FILE_NAME:-$DEFAULT_NAME}"
# Create the file with a unique name
mkdir -p "$HOME/Maler/New Files"
i=1
while [[ -e "$HOME/Maler/New Files/$FILE_NAME" ]]; do
FILE_NAME="${FILE_NAME%.*}_$(printf "%03d" $i).${FILE_NAME##*.}"
i=$((i+1))
done
touch "$HOME/Maler/New Files/$FILE_NAME"
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
# COPY TO THIS FOLDER: ~/.config
#
XDG_DESKTOP_DIR="$HOME/Skrivebord"
XDG_DOWNLOAD_DIR="$HOME/Nedlastinger"
XDG_TEMPLATES_DIR="$HOME/Maler"
XDG_PUBLICSHARE_DIR="$HOME/Offentlig"
XDG_DOCUMENTS_DIR="$HOME/Dokumenter"
XDG_MUSIC_DIR="$HOME/Musikk"
XDG_PICTURES_DIR="$HOME/Bilder"
XDG_VIDEOS_DIR="$HOME/Videoklipp"
XDG_TEMPLATES_DIR="$HOME/Maler"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment