diff --git a/configs/gnome/desktop-settings.sh b/configs/gnome/desktop-settings.sh index c0867be..634ab70 100644 --- a/configs/gnome/desktop-settings.sh +++ b/configs/gnome/desktop-settings.sh @@ -55,7 +55,7 @@ if [ "$keybindings" = "[]" ] || [ "$keybindings" = "@as []" ]; then # Allow Mod+Shift+Enter to open python gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ name "Python REPL" - gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ command "gnome-terminal -- python3" + gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ command "gnome-terminal -- $EWCONFIG_ROOT/.config/ewconfig/scripts/tinker" gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ binding "Return" fi diff --git a/configs/python/python_startup.py b/configs/python/python_startup.py new file mode 100644 index 0000000..0c4a03c --- /dev/null +++ b/configs/python/python_startup.py @@ -0,0 +1,95 @@ +"""Python Startup file. Used to customize the Python REPL""" +import sys +import os + +# Global stuff +IS_IN_TINKER_MODE = bool(os.environ.get("PYTHON_TINKER_MODE")) +COLOR_ALLOWED = not bool(os.environ.get("NO_COLOR")) + + +def colored_string(text: str, color: str) -> str: + if COLOR_ALLOWED: + return "\033[" + color + "m" + text + "\033[0m" + else: + return text + + +# Configure the prompt +class Prompt: + def __init__(self): + self.prompt = colored_string(">>> ", "36") + + def __str__(self): + return self.prompt + + +class MultiLinePrompt: + def __str__(self): + return colored_string("... ", "33") + # return " " + + +# Hook up the prompts +sys.ps1 = Prompt() +sys.ps2 = MultiLinePrompt() + +# "Tinker mode" - automatically import common things +if IS_IN_TINKER_MODE: + print( + colored_string( + "Running in tinker mode. Additional modules are available.", "33" + ) + ) + + # Basics + import time + import json + from pathlib import Path + from dataclasses import dataclass + from typing import ( + List, + Dict, + Tuple, + Set, + Optional, + Union, + Any, + Callable, + Iterable, + Generator, + ) + from pprint import pprint + from datetime import datetime + from textwrap import dedent + from base64 import b64encode, b64decode + + # Math stuff + try: + import numpy as np + + np.set_printoptions(suppress=True) + _vec = lambda *fields: np.array([*fields]) + pi = np.pi + except ImportError: + pass + try: + from pyquaternion import Quaternion + except ImportError: + pass + try: + import matplotlib.pyplot as plt + except ImportError: + pass + + +# If we aren't in tinker mode, un-import sys and os +if not IS_IN_TINKER_MODE: + del sys + del os + +# Clean up other stuff +del IS_IN_TINKER_MODE +del COLOR_ALLOWED +del colored_string +del Prompt +del MultiLinePrompt \ No newline at end of file diff --git a/configs/shells/bash/.bashrc b/configs/shells/bash/.bashrc index abe2c23..b7782d2 100644 --- a/configs/shells/bash/.bashrc +++ b/configs/shells/bash/.bashrc @@ -12,5 +12,9 @@ export PATH="$HOME/bin:$PATH" export PATH="$EWCONFIG_ROOT/scripts:$PATH" export PATH="$HOME/.local/bin:$PATH" +# I want to be able to load my custom python modules +export PYTHONPATH="$EWCONFIG_ROOT/python_modules:$PYTHONPATH" +export PYTHONSTARTUP="$EWCONFIG_ROOT/configs/python/python_startup.py" + # A basic prompt to display user@host dir sign export PS1="(${PS1_CTX:-bash}) \[\e[0;32m\]\u@\h \[\e[0;36m\]\w \[\e[0;36m\]\$ \[\e[0m\]" diff --git a/configs/shells/zsh/.zshrc b/configs/shells/zsh/.zshrc index bd683b8..c81007e 100644 --- a/configs/shells/zsh/.zshrc +++ b/configs/shells/zsh/.zshrc @@ -27,6 +27,7 @@ export LD_LIBRARY_PATH="/usr/local/lib64:$LD_LIBRARY_PATH" # I want to be able to load my custom python modules export PYTHONPATH="$EWCONFIG_ROOT/python_modules:$PYTHONPATH" +export PYTHONSTARTUP="$EWCONFIG_ROOT/configs/python/python_startup.py" # Configure a sane default editor if type -p nvim > /dev/null; then diff --git a/install-linux.sh b/install-linux.sh index 934bd47..0406ba2 100644 --- a/install-linux.sh +++ b/install-linux.sh @@ -132,8 +132,8 @@ if [ -d ~/.config/blender/3.6 ]; then ln -sf $EWCONFIG_ROOT/configs/blender/3.x/ # -- Finalization -- # On systems that need it, configure Gnome -sh ./configs/gnome/gnome-terminal-settings.sh -sh ./configs/gnome/desktop-settings.sh +sh ./configs/gnome/gnome-terminal-settings.sh || true +sh ./configs/gnome/desktop-settings.sh || true # Attempt to force a termux settings reload on Android devices termux-reload-settings || true diff --git a/scripts/tinker b/scripts/tinker new file mode 100755 index 0000000..2cca4a0 --- /dev/null +++ b/scripts/tinker @@ -0,0 +1,11 @@ +#! /bin/bash +# NOTE: This is a script so that we can launch it from a gnome keybind +set -e + +# If PYTHONSTARTUP is not set, we have to set it +if [ -z "$PYTHONSTARTUP" ]; then + export PYTHONSTARTUP="$HOME/.config/ewconfig/configs/python/python_startup.py" +fi + +# Launch python +PYTHON_TINKER_MODE=1 python3 \ No newline at end of file