38 lines
1.9 KiB
Python
38 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Install only the launcher and Settings entry, with backups; no packages/session changes."""
|
|
import argparse
|
|
from datetime import datetime
|
|
import os
|
|
from pathlib import Path
|
|
import shlex
|
|
import shutil
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--apply', action='store_true', help='write files (default: show plan)')
|
|
args = parser.parse_args()
|
|
repo = Path(__file__).resolve().parent.parent
|
|
home = Path.home()
|
|
data = Path(os.environ.get('XDG_DATA_HOME', home / '.local/share'))
|
|
state = Path(os.environ.get('XDG_STATE_HOME', home / '.local/state'))
|
|
launcher = home / '.local/bin/adaptive-shell'
|
|
exec_path = str(launcher).replace('\\', '\\\\').replace('"', '\\"').replace('`', '\\`').replace('$', '\\$').replace('%', '%%')
|
|
files = {
|
|
launcher: '#!/bin/sh\nexec ' + shlex.quote(str(repo / 'hypr/bin/adaptive-shell')) + ' "$@"\n',
|
|
data / 'applications/adaptive-settings.desktop': '[Desktop Entry]\nType=Application\nName=Settings\nComment=Adaptive shell settings\nExec="' + exec_path + '" settings\nIcon=preferences-system\nTerminal=false\nCategories=Settings;DesktopSettings;\n',
|
|
}
|
|
backup = state / 'adaptive-shell/backups' / datetime.now().strftime('%Y%m%d-%H%M%S-%f')
|
|
for i, (path, contents) in enumerate(files.items()):
|
|
print(('WRITE ' if args.apply else 'PLAN ') + str(path))
|
|
if args.apply:
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
if path.exists() or path.is_symlink():
|
|
backup.mkdir(parents=True, exist_ok=True)
|
|
shutil.copy2(path, backup / (str(i) + '-' + path.name), follow_symlinks=True)
|
|
temporary = path.with_name(path.name + '.adaptive-tmp')
|
|
with temporary.open('x') as stream:
|
|
stream.write(contents)
|
|
temporary.chmod(0o755 if path == launcher else 0o644)
|
|
temporary.replace(path)
|
|
if args.apply:
|
|
print('Backups (if needed):', backup)
|