2021-09-23 01:38:18 +00:00
|
|
|
# general shit
|
2022-02-02 04:24:26 +00:00
|
|
|
if $HOSTNAME == "riley-laptop":
|
2021-11-08 20:44:55 +00:00
|
|
|
$PROMPT = '{RED} <3 {RESET}| {BOLD_GREEN}{cwd_base}{RESET} ) '
|
2022-02-02 04:24:26 +00:00
|
|
|
elif $HOSTNAME == "riley-server":
|
|
|
|
$PROMPT = '{RED} <> {RESET}| {BOLD_GREEN}{cwd_base}{RESET} ) '
|
|
|
|
elif $HOSTNAME == "riley-desktop":
|
|
|
|
$PROMPT = '{RED} >< {RESET}| {BOLD_GREEN}{cwd_base}{RESET} ) '
|
2021-09-25 19:08:51 +00:00
|
|
|
$XONSH_COLOR_STYLE = 'default'
|
2021-12-07 08:37:15 +00:00
|
|
|
xontrib load argcomplete autovox jedi z bashisms
|
|
|
|
|
|
|
|
class CommandNotFoundException(Exception):
|
|
|
|
def __init__(self, command):
|
|
|
|
super().__init__(f"Command '{command}' not found.")
|
|
|
|
|
2022-01-27 07:26:41 +00:00
|
|
|
# Windows Subsystem for Linux stuff
|
|
|
|
|
|
|
|
def in_wsl() -> bool:
|
|
|
|
version = p'/proc/version'.read_text()
|
|
|
|
if "microsoft" in version:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
if in_wsl():
|
|
|
|
$GPG_TTY=$(tty)
|
|
|
|
|
2021-12-07 08:37:15 +00:00
|
|
|
def to_clipboard(text: str):
|
2022-01-27 07:26:41 +00:00
|
|
|
if in_wsl():
|
|
|
|
$(echo -n @(text) | clip.exe)
|
|
|
|
else:
|
|
|
|
requires("xclip")
|
|
|
|
$(echo -n @(text) | xclip -sel clipboard)
|
2021-12-07 08:37:15 +00:00
|
|
|
|
|
|
|
def requires(command: str):
|
|
|
|
if not !(which @(command)):
|
|
|
|
raise CommandNotFoundException(command)
|
|
|
|
return True
|
2021-09-22 03:46:08 +00:00
|
|
|
|
2021-09-22 07:52:45 +00:00
|
|
|
# path stuff
|
|
|
|
|
2021-10-20 03:09:24 +00:00
|
|
|
def load_path():
|
|
|
|
import sys
|
|
|
|
$PATH.extend([
|
|
|
|
'~/addins',
|
|
|
|
'~/.local/bin',
|
|
|
|
'~/bin',
|
2021-12-04 05:41:27 +00:00
|
|
|
'~/go/bin',
|
|
|
|
'~/.deno/bin',
|
2021-10-20 03:09:24 +00:00
|
|
|
])
|
|
|
|
sys.path.insert(0, '')
|
|
|
|
|
|
|
|
load_path()
|
2021-09-22 07:52:45 +00:00
|
|
|
|
2021-12-07 08:37:15 +00:00
|
|
|
# TODO: Fix with Arch-based distros
|
|
|
|
# import addins # my extra stuffs :p
|
2021-09-23 01:38:18 +00:00
|
|
|
|
|
|
|
def _colortest():
|
|
|
|
import sys
|
|
|
|
for i in range(256):
|
|
|
|
sys.stdout.write(f"\033[48;5;{i}m ")
|
|
|
|
if (i+1) % 16 == 0:
|
|
|
|
sys.stdout.write("\033[0m\n")
|
|
|
|
|
|
|
|
# tmux
|
2021-12-07 08:37:15 +00:00
|
|
|
try:
|
|
|
|
requires("tmux")
|
|
|
|
if $TERM != 'tmux-256color':
|
|
|
|
folder = p'.'
|
|
|
|
tmux -2 new-session -A -s @(folder.resolve().name)
|
|
|
|
exit
|
|
|
|
except CommandNotFoundException:
|
|
|
|
pass
|
2021-09-22 07:52:45 +00:00
|
|
|
|
2021-09-22 03:46:08 +00:00
|
|
|
# debug
|
|
|
|
def _debug():
|
|
|
|
if $XONSH_SHOW_TRACEBACK:
|
|
|
|
$XONSH_SHOW_TRACEBACK = False
|
|
|
|
print("Debug mode disabled.")
|
|
|
|
else:
|
|
|
|
$XONSH_SHOW_TRACEBACK = True
|
|
|
|
print("Debug mode enabled.")
|
|
|
|
|
|
|
|
# bitwarden shit
|
2021-12-07 08:37:15 +00:00
|
|
|
def bw_get(object: str, bw_id: str, nulled: bool = False):
|
|
|
|
if nulled:
|
|
|
|
return !(bw get @(object) @(bw_id) a> /dev/null)
|
|
|
|
return $(bw get @(object) @(bw_id))
|
|
|
|
|
|
|
|
def _bwc(args: list):
|
|
|
|
requires("bw")
|
|
|
|
if not p'~/.bw_session'.exists():
|
2021-09-23 01:38:18 +00:00
|
|
|
raise FileNotFoundError("~/.bw_session")
|
2021-12-07 08:37:15 +00:00
|
|
|
source ~/.bw_session
|
|
|
|
|
|
|
|
if args[0] == "full": # determine which keys to search for.
|
|
|
|
items = ["username", "password", "totp"]
|
|
|
|
elif args[0] == "password":
|
|
|
|
items = ["password", "totp"]
|
|
|
|
else:
|
|
|
|
items = [args[0]]
|
|
|
|
|
|
|
|
for i in items: # removes keys that don't exist for the object.
|
|
|
|
if not bw_get(i, args[1], True):
|
|
|
|
items.remove(i)
|
|
|
|
|
|
|
|
print(f"found: {', '.join(items)}")
|
|
|
|
for i in items: # actually copy the info to clipboard.
|
|
|
|
output = bw_get(i, args[1])
|
|
|
|
to_clipboard(output)
|
|
|
|
if items.index(i) < len(items) - 1:
|
|
|
|
input(f"copied {i}, press enter to continue")
|
|
|
|
else:
|
|
|
|
print(f"copied {i}")
|
2021-09-22 03:46:08 +00:00
|
|
|
|
2021-11-08 04:36:58 +00:00
|
|
|
def _ensure_tmux(args: list):
|
|
|
|
if $XONSH_SHOW_TRACEBACK:
|
|
|
|
print(args)
|
|
|
|
if not $(tmux has-session -t @(args[0])):
|
|
|
|
tmux new-session -d -s @(args[0]) all> /dev/null
|
|
|
|
$(tmux send-keys -t @(args[0]) @(f"cd {args[1]}") C-m)
|
|
|
|
$(tmux send-keys -t @(args[0]) @(f"{args[2]}") C-m)
|
|
|
|
|
|
|
|
def _alias():
|
|
|
|
for alias in aliases:
|
|
|
|
if callable(aliases[alias]):
|
|
|
|
print(alias + " = ", aliases[alias].__name__)
|
|
|
|
else:
|
|
|
|
print(alias + " =", " ".join(aliases[alias]))
|
|
|
|
|
2021-11-11 04:41:18 +00:00
|
|
|
def _mcrcon(args: list):
|
|
|
|
if p"~/.mcrcon".exists():
|
|
|
|
source "~/.mcrcon"
|
|
|
|
else:
|
|
|
|
raise FileNotFoundError("~/.mcrcon")
|
|
|
|
$(mcrcon @(" ".join(args)))
|
|
|
|
|
|
|
|
def _mcterm():
|
|
|
|
if p"~/.mcrcon".exists():
|
|
|
|
source "~/.mcrcon"
|
|
|
|
else:
|
|
|
|
raise FileNotFoundError("~/.mcrcon")
|
|
|
|
mcrcon -t
|
|
|
|
|
2021-12-04 05:41:27 +00:00
|
|
|
def _add_system_user(args: list):
|
|
|
|
"""used to add a system user for systemd services"""
|
|
|
|
$(adduser --system --home @(args[1]))
|
|
|
|
$(addgroup --system @(args[0]))
|
|
|
|
$(adduser @(args[0]) @(args[0]))
|
|
|
|
|
2021-09-23 01:38:18 +00:00
|
|
|
# aliases
|
|
|
|
aliases.update({
|
|
|
|
'bwg': _bwc,
|
|
|
|
'bwc': _bwc,
|
|
|
|
'colortest': _colortest,
|
|
|
|
'config': '/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME',
|
|
|
|
'debug': _debug,
|
|
|
|
'ls': 'ls -alhs --color=auto',
|
2021-11-11 04:41:18 +00:00
|
|
|
'mc': _mcrcon,
|
|
|
|
'mct': _mcterm,
|
2021-09-23 01:38:18 +00:00
|
|
|
':q': 'exit',
|
2021-10-20 03:09:24 +00:00
|
|
|
'owo': 'echo uwu',
|
2022-01-26 20:58:37 +00:00
|
|
|
'awa': 'echo ewe',
|
|
|
|
'ewe': 'echo iwi',
|
|
|
|
'iwi': 'echo awa',
|
|
|
|
'uwu': 'echo owo',
|
|
|
|
'ywy': 'echo whywhy',
|
2021-11-08 04:36:58 +00:00
|
|
|
'ensure-tmux': _ensure_tmux,
|
|
|
|
'alias': _alias,
|
2022-01-26 20:58:37 +00:00
|
|
|
'asu': _add_system_user,
|
|
|
|
'l': '/home/riley/programs/light_controller/main.py'
|
2021-09-23 01:38:18 +00:00
|
|
|
})
|
2021-09-22 07:52:45 +00:00
|
|
|
|
2022-02-02 04:24:26 +00:00
|
|
|
if in_wsl():
|
|
|
|
aliases.update({
|
|
|
|
'wh': "cd /mnt/c/Users/Riley"
|
|
|
|
})
|
|
|
|
|
2021-09-23 01:38:18 +00:00
|
|
|
# man page colors :O
|
|
|
|
$LESS_TERMCAP_mb = "\033[01;31m" # begin blinking
|
|
|
|
$LESS_TERMCAP_md = "\033[01;31m" # begin bold
|
|
|
|
$LESS_TERMCAP_me = "\033[0m" # end mode
|
|
|
|
$LESS_TERMCAP_so = "\033[01;44;36m" # begin standout-mode (bottom of screen)
|
|
|
|
$LESS_TERMCAP_se = "\033[0m" # end standout-mode
|
2021-09-25 19:08:51 +00:00
|
|
|
|