diff --git a/aliases.txt b/aliases.txt index b6a8171..47bf4b9 100644 --- a/aliases.txt +++ b/aliases.txt @@ -1,6 +1,4 @@ build="docker compose run --rm ner-gcc-arm make" -flash="probe-rs download --verify --chip STM32F405RGTx ./build/*.elf && probe-rs reset --chip STM32F405RGTx" -debug="{(probe-rs gdb --reset-halt --gdb-connection-string 0.0.0.0:1337 --chip STM32F405RGTx)&} && ID=$! && sleep 1 && docker compose run --rm -P ner-gcc-arm "arm-none-eabi-gdb" /home/app$(ls ./build/*.elf | cut -c2-) -ex "target remote host.docker.internal:1337" && kill $ID && probe-rs reset --chip STM32F405RGTx" cerbcon="sudo usbip attach -r 192.168.100.12 -b 1-1.3" shepcon="sudo usbip attach -r 192.168.100.12 -b 1-1.4" -peyton="echo \" Shut the fuck up Peyton, fucking hell\" " +peyton="echo \" Shut the fuck up Peyton, fucking hell\" " \ No newline at end of file diff --git a/clang_restage.py b/clang_restage.py index 9285e97..a4597f4 100644 --- a/clang_restage.py +++ b/clang_restage.py @@ -16,8 +16,6 @@ def main(): # Get a list of staged files staged_files = get_staged_files() - - # Run clang-format on staged files result = subprocess.run(['clang-format', '-i', '--style=file', '--fallback-style=Google'] + staged_files, ) diff --git a/load_alias.py b/load_alias.py new file mode 100644 index 0000000..c98cae2 --- /dev/null +++ b/load_alias.py @@ -0,0 +1,65 @@ +import os +import platform +import sys + +def load_aliases(venv_path, aliases_file): + os_type = platform.system() + if os_type == 'Windows': + activate_path = os.path.join(venv_path, 'Scripts', 'activate') # Bash script for Git Bash on Windows + else: + activate_path = os.path.join(venv_path, 'bin', 'activate') # bash script for Unix-like systems + + try: + # Read existing aliases from the activation script + if os.path.exists(activate_path): + with open(activate_path, 'r') as activate_file: + existing_aliases = activate_file.readlines() + else: + existing_aliases = [] + + # Convert the existing aliases to a set for easy comparison + existing_aliases_set = set() + for line in existing_aliases: + if line.startswith('alias '): + alias_definition = line.strip() + alias_name = alias_definition.split('=')[0].replace('alias ', '') + existing_aliases_set.add(alias_name) + + # Read aliases from the provided aliases file + with open(aliases_file, 'r') as f: + aliases = f.readlines() + + # Prepare to write new aliases that aren't already in the activate script + new_aliases = [] + for alias in aliases: + alias_name, alias_command = alias.strip().split('=', 1) + alias_name = alias_name.strip() + alias_command = alias_command.strip('"') + + if alias_name not in existing_aliases_set: + new_aliases.append(f'alias {alias_name}="{alias_command}"\n') + + # Append new aliases to the activation script if there are any + if new_aliases: + with open(activate_path, 'a') as activate_file: + activate_file.write('\n# Aliases\n') + activate_file.writelines(new_aliases) + print(f"Added {len(new_aliases)} new alias(es) to the activation script.") + else: + print("No new aliases to add; all are already present.") + + except Exception as e: + print(f"Failed to update aliases: {e}", file=sys.stderr) + sys.exit(1) + +def main(): + current_directory = os.path.dirname(os.path.abspath(__file__)) + parent_directory = os.path.dirname(current_directory) + venv_path = os.path.join(parent_directory, 'ner-venv') + aliases_file = os.path.join(current_directory, 'aliases.txt') + + load_aliases(venv_path, aliases_file) + print("Close and reopen your terminal or the venv for changes to take effect.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/setup.py b/setup.py index 2956a37..58aa45f 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ def parse_requirements(filename): setup( name='ner-setup', version='0.1', - py_modules=['ner_setup', 'launchpad', 'clang_restage', 'miniterm'], + py_modules=['ner_setup', 'launchpad', 'clang_restage', 'miniterm' , 'load_alias'], install_requires=parse_requirements('requirements.txt'), entry_points={ 'console_scripts': [ @@ -16,6 +16,7 @@ def parse_requirements(filename): 'clang_restage=clang_restage:main', 'serial=miniterm:main', 'launchpad=launchpad:main', + 'load-alias=load_alias:main', ], },