mirror of
https://github.com/JonasunderscoreJones/BashCommandAliasEditor.git
synced 2025-10-22 21:09:19 +02:00
Release of v2.0 and small repo tweaks
- Release of v2.0 - Modified Readme.md
This commit is contained in:
parent
97cb7bdf50
commit
5ffb6a9e11
4 changed files with 82 additions and 9 deletions
24
README.md
24
README.md
|
@ -1,14 +1,20 @@
|
|||
# LinuxCommandAliasEditor
|
||||
This program helps you to create and edit command aliases on Linux and MacOS
|
||||
# BashCommandAliasEditor
|
||||
This program helps you to create and edit command aliases on Linux and MacOS (with the Bash Shell)
|
||||
|
||||
# How to use
|
||||
### Windows and Linux
|
||||
1. Download the executable for your OS (clearly labeled) and execute it.
|
||||
|
||||
### MacOS (manually) and Windows and Linux (alternative to above)
|
||||
1. Download the most recent verson of the python file
|
||||
2. Open a terminal and locate your Download directory ( if Downloaded in the default downlaods folder type: 'cd ~/Downloads'
|
||||
3. type 'python3 --version' to check if python is installed (install python if not already installed)
|
||||
4. type 'python3 [name_of_python-file] (example: 'python3 command_alias-editor_v1.0'
|
||||
5. The program should be executed. Follow all further instructions shown in the terminal
|
||||
6. Dont forget to execute 'source ~/.bashrc' at the end (when the program tells you to)
|
||||
3. type 'python3 --version' to check if python is installed (install python3 if not already installed)
|
||||
4. Install all Dependencies. os: `pip3 install os` (install pip3 if not already installed)
|
||||
5. type 'python3 [name_of_python-file] (example: 'python3 command_alias-editor_v1.0'
|
||||
6. The program should be executed. Follow all further instructions shown in the terminal
|
||||
7. Dont forget to execute 'source ~/.bashrc' at the end.
|
||||
|
||||
# Possible Updates
|
||||
- editor for existing aliases
|
||||
- graphical user interface (GUI) for the program
|
||||
### Why do I have to manualy execute 'source ~/.bashrc'?
|
||||
The reason that this can't be done by the program itself is that it wouldn't be applied to the main shell but only for the runtime of the program itself. After the program exits, all changes will be reverted.
|
||||
|
||||
This problem could technically be solved by using subprocesses but ffs I'm not in the mood for doing that. It's some work which I don't wanna do
|
BIN
command_alias_editor-v2.0-linux
Executable file
BIN
command_alias_editor-v2.0-linux
Executable file
Binary file not shown.
BIN
command_alias_editor-v2.0-windows.exe
Normal file
BIN
command_alias_editor-v2.0-windows.exe
Normal file
Binary file not shown.
67
command_alias_editor-v2.0.py
Normal file
67
command_alias_editor-v2.0.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
VERSION = "2.0"
|
||||
|
||||
def main():
|
||||
try:
|
||||
from os import system, mkdir
|
||||
import os.path
|
||||
|
||||
# STEP ONE save directory for the Shell Script Files
|
||||
print("Welcome to Bash Command Alias Editor v" + VERSION + " by Jonas_Jones")
|
||||
print("\n1. Set the script directory (leave blank for default):")
|
||||
save_directory = input("~/")
|
||||
if save_directory == "":
|
||||
save_directory = os.path.expanduser("~") + "/.sh"
|
||||
else:
|
||||
save_directory = os.path.expanduser("") + "/" + save_directory
|
||||
print("Directory set to " + save_directory)
|
||||
|
||||
try:
|
||||
if not os.path.exists(save_directory):
|
||||
os.mkdir(save_directory)
|
||||
print("uwu")
|
||||
except:
|
||||
print("Something went wrong while creating the directory.")
|
||||
exit()
|
||||
|
||||
# STEP TWO command alias name
|
||||
print("\n2. Choose the name for the command alias:")
|
||||
command_alias = input(save_directory + "/")
|
||||
print("Command Alias script for '" + command_alias + "' is saved at '" + save_directory + "/" + command_alias)
|
||||
|
||||
# STEP THREE commands to be executed
|
||||
print("\n3. Type the command(s) you wish to be executed upn running the alias. Press Enter for new lines, press enter on empty line to quit the editor.")
|
||||
command = None
|
||||
print(save_directory + "/" + command_alias + ".sh")
|
||||
|
||||
command_alias_file = open(save_directory + "/" + command_alias + ".sh", 'w')
|
||||
|
||||
command_alias_file.write("#! /usr/bin/sh\n")
|
||||
|
||||
while command != "":
|
||||
command = input(">> ")
|
||||
command_alias_file.write(command + "\n")
|
||||
command_alias_file.close()
|
||||
|
||||
# STEP FOUR Apply alias to shell
|
||||
print("\n4. Applying alias to the shell.")
|
||||
try:
|
||||
bashrc = open(os.path.expanduser('~') + "/.bashrc", "a")
|
||||
bashrc.write("\nalias " + command_alias + "='" + save_directory + "/" + command_alias + ".sh'")
|
||||
bashrc.close()
|
||||
except:
|
||||
print("ERROR: Couldn't open the bashrc file. Are you using the Bash shell? Is the file missing or requires higher permission levels?")
|
||||
exit()
|
||||
system("./.temp.sh")
|
||||
system("chmod u+x " + save_directory + "/" + command_alias + ".sh")
|
||||
system("rm .temp.sh")
|
||||
print("Execute the command 'source ~/.bashrc' in the terminal to complete the final step.")
|
||||
|
||||
|
||||
|
||||
except:
|
||||
print("Something went wrong. Please make sure that all dependencies are installed.")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue