Compare commits

..

No commits in common. "48ce6c87a6e511d5518b64e88c744da6e2ebb0b1" and "62b809bd3c7662174ffa65ab26e999d12c365996" have entirely different histories.

6 changed files with 8 additions and 181 deletions

@ -2,7 +2,6 @@
mkdir -p ~/.local/bin mkdir -p ~/.local/bin
cp dotfiles/.local/bin/commands ~/.local/bin/commands cp dotfiles/.local/bin/commands ~/.local/bin/commands
cp dotfiles/.local/bin/gnome-shortcuts-macbook-air ~/.local/bin/
mkdir -p ~/.sway mkdir -p ~/.sway
cp dotfiles/.sway/config ~/.sway/config cp dotfiles/.sway/config ~/.sway/config
cp dotfiles/.zshenv ~/.zshenv cp dotfiles/.zshenv ~/.zshenv

@ -21,17 +21,16 @@ import sys
import tempfile import tempfile
import time import time
import traceback import traceback
from typing import (Literal, Optional,)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def custom_notify( def custom_notify(
title: Optional[str]=None, title=None,
msg: Optional[str]=None, msg=None,
timeout: Optional[int]=None, timeout=None,
) -> None: ):
if timeout is None: if timeout is None:
timeout = 5 timeout = 5
@ -1684,7 +1683,7 @@ def pm_service(argv):
print('') print('')
def scrap_yt_music(argv: Iterable[str]) -> None: def scrap_yt_music(argv):
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option( parser.add_option(
'--verbose', '--verbose',
@ -1930,16 +1929,6 @@ def desktop_services(argv):
type=int, type=int,
help='0 - mac book air (no turbo boost, max pct 30, every 4 seconds', help='0 - mac book air (no turbo boost, max pct 30, every 4 seconds',
) )
parser.add_option(
'--cpufreq-action',
dest='cpufreq_action',
default=None,
choices=[
'performance',
'powersave',
],
#type=str,
)
parser.add_option( parser.add_option(
'--battery', '--battery',
dest='battery', dest='battery',
@ -2371,39 +2360,6 @@ def desktop_services(argv):
return state return state
class Cpufreq:
@classmethod
@property
def profile(cls) -> Literal['applesmc.768']:
if os.path.exists('/sys/bus/platform/devices/applesmc.768'):
return 'applesmc.768'
else:
raise NotImplementedError
@classmethod
def powersave(cls):
if cls.profile == 'applesmc.768':
subprocess.check_call(r'''
echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
echo powersave | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
echo 1 > /sys/bus/platform/devices/applesmc.768/fan1_manual;
echo 2000 > /sys/bus/platform/devices/applesmc.768/fan1_output;
''', shell=True)
else:
raise NotImplementedError
@classmethod
def performance(cls):
if cls.profile == 'applesmc.768':
subprocess.check_call(r'''
echo powersave | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
echo 1 > /sys/bus/platform/devices/applesmc.768/fan1_manual;
echo 6500 > /sys/bus/platform/devices/applesmc.768/fan1_output;
''', shell=True)
else:
raise NotImplementedError
if options.backlight_increase or options.backlight_decrease: if options.backlight_increase or options.backlight_decrease:
if options.backlight_increase: if options.backlight_increase:
direction = Backlight.Direction.increase direction = Backlight.Direction.increase
@ -2418,16 +2374,6 @@ echo 6500 > /sys/bus/platform/devices/applesmc.768/fan1_output;
) )
return return
elif not options.cpufreq_action is None:
if options.cpufreq_action == 'performance':
Cpufreq.performance()
elif options.cpufreq_action == 'powersave':
Cpufreq.powersave()
else:
raise NotImplementedError
return
else: else:
pass pass
@ -2906,99 +2852,6 @@ def suspend_timer(argv):
print("suspend computer at %s" % t1.isoformat()) print("suspend computer at %s" % t1.isoformat())
subprocess.check_call(["systemctl", "suspend"]); subprocess.check_call(["systemctl", "suspend"]);
def gnome_shortcuts(argv: list[str]) -> None:
parser = optparse.OptionParser()
parser.add_option(
'-a', '--add',
action='store_true',
default=None,
)
parser.add_option(
'-l', '--list',
action='store_true',
default=None,
)
options, args = parser.parse_args(argv)
def commands_ids() -> list[str]:
bindings = subprocess.check_output([
'gsettings', 'get', 'org.gnome.settings-daemon.plugins.media-keys',
'custom-keybindings',
]).decode('utf-8').strip().replace('\'', '"',)
if bindings == '@as []':
t1 = []
else:
t1 = json.loads(bindings)
return t1
def add_command(name, command, binding):
command_id = len(commands_ids())
for cmd in [
(
'gsettings', 'set', 'org.gnome.settings-daemon.plugins.media-keys',
'custom-keybindings', '[%s]' % ','.join([
"'%s'" % \
(
'/org/gnome/settings-daemon/plugins/media-keys'
'/custom-keybindings/custom%d/'
) % o
for o in range(command_id + 1)
]),
),
(
'gsettings', 'set',
(
'org.gnome.settings-daemon.plugins.media-keys.custom-keybinding'
':/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom%d/'
) % command_id,
'name', name,
),
(
'gsettings', 'set',
(
'org.gnome.settings-daemon.plugins.media-keys.custom-keybinding'
':/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom%d/'
) % command_id,
'command', command,
),
(
'gsettings', 'set',
(
'org.gnome.settings-daemon.plugins.media-keys.custom-keybinding'
':/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom%d/'
) % command_id,
'binding', binding,
),
]:
subprocess.check_call(cmd)
if options.list:
t1 = commands_ids()
t2 = [
{
k : json.loads(subprocess.check_output([
'gsettings', 'get',
(
'org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:%s'
) % o,
k,
]).decode('utf-8').replace('\'', '"',))
for k in ['name', 'binding', 'command']
}
for o in t1
]
pprint.pprint(t2)
elif options.add:
add_command(*args)
else:
raise NotImplementedError
def socat_ssh(argv): def socat_ssh(argv):
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option( parser.add_option(
@ -3433,7 +3286,7 @@ def media_keys(argv):
'mocp', 'mocp',
], stdout=subprocess.PIPE) == 0 ], stdout=subprocess.PIPE) == 0
def mocp_info() -> str: def mocp_info():
t1 = subprocess.check_output(['mocp', '-i']) t1 = subprocess.check_output(['mocp', '-i'])
t3 = t1.decode('utf-8') t3 = t1.decode('utf-8')
t2 = dict([ t2 = dict([
@ -3528,13 +3381,13 @@ def media_keys(argv):
msg=msg, msg=msg,
) )
def commands_cli() -> None: def commands_cli():
logging.getLogger().setLevel(logging.INFO) logging.getLogger().setLevel(logging.INFO)
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stderr) handler = logging.StreamHandler(sys.stderr)
logging.getLogger().addHandler(handler) logging.getLogger().addHandler(handler)
msg : Optional[str] = None msg = None
try: try:
if sys.argv[1].startswith('media'): if sys.argv[1].startswith('media'):
@ -3577,8 +3430,6 @@ def commands_cli() -> None:
share_wifi(sys.argv[2:]) share_wifi(sys.argv[2:])
elif sys.argv[1] == 'socat-ssh': elif sys.argv[1] == 'socat-ssh':
socat_ssh(sys.argv[2:]) socat_ssh(sys.argv[2:])
elif sys.argv[1] == 'gnome-shortcuts':
gnome_shortcuts(sys.argv[2:])
elif sys.argv[1] == 'sway_sock': elif sys.argv[1] == 'sway_sock':
print(sway_sock()) print(sway_sock())
elif sys.argv[1] == 'suspend-timer': elif sys.argv[1] == 'suspend-timer':

@ -1,13 +0,0 @@
#!/usr/bin/bash
commands gnome-shortcuts \
-a \
'powersave' \
'commands desktop-services --cpufreq-action powersave' \
'<Shift><Alt>1'
commands gnome-shortcuts \
-a \
'performance' \
'commands desktop-services --cpufreq-action performance' \
'<Shift><Alt>2'

@ -1,6 +1,3 @@
ACTION=="add|change", SUBSYSTEM=="leds", DEVPATH=="/devices/pci0000:00/0000:00:1b.0/hdaudioC0D0/leds/hda::mute", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness" ACTION=="add|change", SUBSYSTEM=="leds", DEVPATH=="/devices/pci0000:00/0000:00:1b.0/hdaudioC0D0/leds/hda::mute", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness"
ACTION=="add|change", SUBSYSTEM=="leds", DEVPATH=="/devices/platform/applesmc.768/leds/smc::kbd_backlight", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness" ACTION=="add|change", SUBSYSTEM=="leds", DEVPATH=="/devices/platform/applesmc.768/leds/smc::kbd_backlight", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness"
ACTION=="add|change", DEVPATH=="/devices/platform/applesmc.768", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/fan1_manual /sys$devpath/fan1_output"
ACTION=="add|change", DEVPATH=="/class/backlight/intel_backlight", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness" ACTION=="add|change", DEVPATH=="/class/backlight/intel_backlight", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness"
ACTION=="add|change", DEVPATH=="/devices/system/cpu/", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/cpufreq/scaling_governor"
ACTION=="add|change", KERNEL=="cpu[0-9]", SUBSYSTEM=="cpu", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/cpufreq/scaling_governor"

6
m

@ -27,11 +27,5 @@ def js(argv):
if len(sys.argv) > 1 and sys.argv[1] == 'js': if len(sys.argv) > 1 and sys.argv[1] == 'js':
js(sys.argv[2:]) js(sys.argv[2:])
elif len(sys.argv) > 1 and sys.argv[1] == 'mypy':
subprocess.check_call([
'mypy',
'--strict',
'dotfiles/.local/bin/commands',
])
else: else:
raise NotImplementedError raise NotImplementedError

@ -6,4 +6,3 @@ pyquery
youtube-dl youtube-dl
gdown gdown
aiohttp aiohttp
mypy