mirror of
https://github.com/ViViDboarder/shoestrap.git
synced 2024-11-22 12:26:29 +00:00
Improve color detection over ssh
This commit is contained in:
parent
06e3aea526
commit
96a2dc9381
@ -1,6 +1,7 @@
|
|||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
from subprocess import Popen, PIPE, check_output
|
from subprocess import Popen, PIPE, check_output
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
@ -42,6 +43,17 @@ def get_terminal_profile(force=False):
|
|||||||
if not force and TERM_VAR in os.environ:
|
if not force and TERM_VAR in os.environ:
|
||||||
return os.environ[TERM_VAR]
|
return os.environ[TERM_VAR]
|
||||||
|
|
||||||
|
# If over SSH, quit. Colorschemes should instead be forwarded
|
||||||
|
if is_ssh():
|
||||||
|
print(
|
||||||
|
("Warning: Cannot derive colors. "
|
||||||
|
"SSH sessions won't allow detecting the terminal profile."
|
||||||
|
f" Instead forward {TERM_VAR} from your source machine."),
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
term_program = os.environ.get("TERM_PROGRAM")
|
term_program = os.environ.get("TERM_PROGRAM")
|
||||||
if term_program == "Apple_Terminal":
|
if term_program == "Apple_Terminal":
|
||||||
tty = check_output(["tty"]).strip()
|
tty = check_output(["tty"]).strip()
|
||||||
@ -53,7 +65,10 @@ def get_terminal_profile(force=False):
|
|||||||
raise SystemError("Could not get results from applescript")
|
raise SystemError("Could not get results from applescript")
|
||||||
return stdout
|
return stdout
|
||||||
elif term_program == "iTerm.app":
|
elif term_program == "iTerm.app":
|
||||||
|
if "ITERM_PROFILE" in os.environ:
|
||||||
return os.environ["ITERM_PROFILE"]
|
return os.environ["ITERM_PROFILE"]
|
||||||
|
else:
|
||||||
|
raise ValueError("Using iTerm but no profile found")
|
||||||
elif term_program == "Alacritty":
|
elif term_program == "Alacritty":
|
||||||
return "Alacritty"
|
return "Alacritty"
|
||||||
|
|
||||||
@ -202,6 +217,12 @@ def print_env(var: str, val: str, export=False, fish=False):
|
|||||||
print(f'set -g {var} "{val}";')
|
print(f'set -g {var} "{val}";')
|
||||||
|
|
||||||
|
|
||||||
|
def is_ssh() -> bool:
|
||||||
|
if os.environ.get("SSH_TTY"):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
if args.print_term:
|
if args.print_term:
|
||||||
|
@ -6,6 +6,8 @@ set -gx XDG_CACHE_HOME "$HOME/.cache"
|
|||||||
# Increase memory sizes for java using Ant
|
# Increase memory sizes for java using Ant
|
||||||
set -gx ANT_OPTS "-Xmx2048m -Xms512m"
|
set -gx ANT_OPTS "-Xmx2048m -Xms512m"
|
||||||
|
|
||||||
|
# Interractive env variables
|
||||||
|
if status --is-interactive
|
||||||
# FZF
|
# FZF
|
||||||
if type -q rg
|
if type -q rg
|
||||||
set -gx FZF_DEFAULT_COMMAND 'rg --files'
|
set -gx FZF_DEFAULT_COMMAND 'rg --files'
|
||||||
@ -24,3 +26,4 @@ set -gx FZF_DEFAULT_OPTS "
|
|||||||
|
|
||||||
# Export colors
|
# Export colors
|
||||||
eval ($HOME/bin/derive_colors.py --export --fish)
|
eval ($HOME/bin/derive_colors.py --export --fish)
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user