From 6d49aa0f5b74ee0fdb6a8de4a779020c31906c4d Mon Sep 17 00:00:00 2001 From: Simon Cornet Date: Sun, 24 Mar 2024 19:56:47 +0100 Subject: [PATCH] [repo] small reorganisation --- {clipse => apps/clipse}/custom_theme.json | 0 {screenshot => apps/screenshot}/screenshot.sh | 0 {ssh => apps/ssh}/config | 0 {swaylock => apps/swaylock}/lock.sh | 0 {wallpaper => apps/wallpaper}/startup.sh | 0 {waybar => apps/waybar}/startup.sh | 4 +- {waybar => apps/waybar}/style.css | 5 - {waybar => apps/waybar}/waybar.conf | 13 +- {wireguard => apps/wireguard}/wireguard.sh | 2 +- {wofi => apps/wofi}/style.css | 0 {wofi => apps/wofi}/wofi.sh | 0 hyprland/conf.d/bindings.conf | 10 +- hyprland/conf.d/executions.conf | 4 +- nix/home/ssh/ssh.nix | 2 +- nix/home/zsh/zsh.nix | 4 +- waybar/spotify.py | 178 ------------------ 16 files changed, 15 insertions(+), 207 deletions(-) rename {clipse => apps/clipse}/custom_theme.json (100%) rename {screenshot => apps/screenshot}/screenshot.sh (100%) rename {ssh => apps/ssh}/config (100%) rename {swaylock => apps/swaylock}/lock.sh (100%) rename {wallpaper => apps/wallpaper}/startup.sh (100%) rename {waybar => apps/waybar}/startup.sh (54%) rename {waybar => apps/waybar}/style.css (94%) rename {waybar => apps/waybar}/waybar.conf (88%) rename {wireguard => apps/wireguard}/wireguard.sh (95%) rename {wofi => apps/wofi}/style.css (100%) rename {wofi => apps/wofi}/wofi.sh (100%) delete mode 100644 waybar/spotify.py diff --git a/clipse/custom_theme.json b/apps/clipse/custom_theme.json similarity index 100% rename from clipse/custom_theme.json rename to apps/clipse/custom_theme.json diff --git a/screenshot/screenshot.sh b/apps/screenshot/screenshot.sh similarity index 100% rename from screenshot/screenshot.sh rename to apps/screenshot/screenshot.sh diff --git a/ssh/config b/apps/ssh/config similarity index 100% rename from ssh/config rename to apps/ssh/config diff --git a/swaylock/lock.sh b/apps/swaylock/lock.sh similarity index 100% rename from swaylock/lock.sh rename to apps/swaylock/lock.sh diff --git a/wallpaper/startup.sh b/apps/wallpaper/startup.sh similarity index 100% rename from wallpaper/startup.sh rename to apps/wallpaper/startup.sh diff --git a/waybar/startup.sh b/apps/waybar/startup.sh similarity index 54% rename from waybar/startup.sh rename to apps/waybar/startup.sh index 3c4ed19..d026164 100755 --- a/waybar/startup.sh +++ b/apps/waybar/startup.sh @@ -5,6 +5,6 @@ pkill waybar # start waybar waybar \ - -c ~/.dotfiles/waybar/waybar.conf \ - -s ~/.dotfiles/waybar/style.css \ + -c ~/.dotfiles/apps/waybar/waybar.conf \ + -s ~/.dotfiles/apps/waybar/style.css \ & diff --git a/waybar/style.css b/apps/waybar/style.css similarity index 94% rename from waybar/style.css rename to apps/waybar/style.css index b0c3f81..43c4e39 100644 --- a/waybar/style.css +++ b/apps/waybar/style.css @@ -60,11 +60,6 @@ tooltip { color: #89b4fa; } -#custom-spotify { - padding: 5px 5px; - margin-top: 10px; -} - #memory { color: #a6e3a1; } diff --git a/waybar/waybar.conf b/apps/waybar/waybar.conf similarity index 88% rename from waybar/waybar.conf rename to apps/waybar/waybar.conf index c350ad4..566fc63 100644 --- a/waybar/waybar.conf +++ b/apps/waybar/waybar.conf @@ -81,17 +81,8 @@ "custom/wireguard": { "interval": 2, "format": "{}", - "exec": "$HOME/.dotfiles/wireguard/wireguard.sh status", - "on-click": "$HOME/.dotfiles/wireguard/wireguard.sh switch" - }, - - "custom/spotify": { - "exec": "/usr/bin/python3 $HOME/.dotfiles/waybar/spotify.py --player spotify", - "format": "{}", - "return-type": "json", - "max-length": 3, - "min-length": 3, - "on-click": "playerctl play-pause" + "exec": "$HOME/.dotfiles/apps/wireguard/wireguard.sh status", + "on-click": "$HOME/.dotfiles/apps/wireguard/wireguard.sh switch" }, "hyprland/window": { diff --git a/wireguard/wireguard.sh b/apps/wireguard/wireguard.sh similarity index 95% rename from wireguard/wireguard.sh rename to apps/wireguard/wireguard.sh index baa2524..b513218 100755 --- a/wireguard/wireguard.sh +++ b/apps/wireguard/wireguard.sh @@ -1,7 +1,7 @@ #!/usr/bin/env zsh # variables -hostname_short=$(/usr/bin/hostname --short) +hostname_short=$(hostname --short) tailscale_bin="tailscale" tailscale_status=$("$tailscale_bin" status) diff --git a/wofi/style.css b/apps/wofi/style.css similarity index 100% rename from wofi/style.css rename to apps/wofi/style.css diff --git a/wofi/wofi.sh b/apps/wofi/wofi.sh similarity index 100% rename from wofi/wofi.sh rename to apps/wofi/wofi.sh diff --git a/hyprland/conf.d/bindings.conf b/hyprland/conf.d/bindings.conf index b41986a..42339b9 100644 --- a/hyprland/conf.d/bindings.conf +++ b/hyprland/conf.d/bindings.conf @@ -9,7 +9,7 @@ $mainMod = SUPER bind = $mainMod, Return, exec, alacritty bind = $mainMod, B, exec, blueman-manager bind = $mainMod, C, exec, alacritty --class clipse --command clipse $PPID -bind = $mainMod, D, exec, ~/.dotfiles/wofi/wofi.sh +bind = $mainMod, D, exec, ~/.dotfiles/apps/wofi/wofi.sh bind = $mainMod, E, exec, nautilus --new-window bind = $mainMod, F, fullscreen bind = $mainMod, J, togglesplit @@ -18,14 +18,14 @@ bind = $mainMod, M, exit, bind = $mainMod, N, exec, alacritty --class nmtui --command ~/.dotfiles/hyprland/nmtui.sh bind = $mainMod, P, pseudo bind = $mainMod, Q, killactive -bind = $mainMod, S, exec, ~/.dotfiles/screenshot/screenshot.sh area -bind = ALT SHIFT, S, exec, ~/.dotfiles/screenshot/screenshot.sh screen +bind = $mainMod, S, exec, ~/.dotfiles/apps/screenshot/screenshot.sh area +bind = ALT SHIFT, S, exec, ~/.dotfiles/apps/screenshot/screenshot.sh screen bind = $mainMod, T, exec, alacritty --class nostt --command nostt bind = $mainMod, V, togglefloating # manage lockscreen -bind = $mainMod, L, exec, ~/.dotfiles/swaylock/lock.sh -bindl = ,switch:on:Lid Switch, exec, ~/.dotfiles/swaylock/lock.sh +bind = $mainMod, L, exec, ~/.dotfiles/apps/swaylock/lock.sh +bindl = ,switch:on:Lid Switch, exec, ~/.dotfiles/apps/swaylock/lock.sh # focus bindings bind = $mainMod, up, movefocus, u diff --git a/hyprland/conf.d/executions.conf b/hyprland/conf.d/executions.conf index 5c8a4c0..5eb0820 100644 --- a/hyprland/conf.d/executions.conf +++ b/hyprland/conf.d/executions.conf @@ -1,5 +1,5 @@ # start waybar -exec = ~/.dotfiles/waybar/startup.sh +exec = ~/.dotfiles/apps/waybar/startup.sh # set monitor workspaces exec = ~/.dotfiles/hyprland/monitor.sh @@ -15,7 +15,7 @@ exec-once = clipse -listen exec = blueman-tray # theming -exec = ~/.dotfiles/wallpaper/startup.sh +exec = ~/.dotfiles/apps/wallpaper/startup.sh # set volume exec-once = wpctl set-volume @DEFAULT_AUDIO_SINK@ 80% diff --git a/nix/home/ssh/ssh.nix b/nix/home/ssh/ssh.nix index c82fc77..42c3033 100644 --- a/nix/home/ssh/ssh.nix +++ b/nix/home/ssh/ssh.nix @@ -4,6 +4,6 @@ # ssh programs.ssh = { enable = true; - includes = [ "${config.home.homeDirectory}/.dotfiles/ssh/config" ]; + includes = [ "${config.home.homeDirectory}/.dotfiles/apps/ssh/config" ]; }; } diff --git a/nix/home/zsh/zsh.nix b/nix/home/zsh/zsh.nix index 406b9ac..73c4049 100644 --- a/nix/home/zsh/zsh.nix +++ b/nix/home/zsh/zsh.nix @@ -42,8 +42,8 @@ system-purge = "sudo nix-collect-garbage -d"; # sshfs - sj-mount-media = "sshfs nas.siempie.local:/tank/media/ /home/simon/remotedir/media"; - sj-mount-siempie = "sshfs nas.siempie.local:/tank/siempie/ /home/simon/remotedir/siempie"; + sj-mount-media = "sshfs nas.siempie.local:/tank/media /home/simon/remotedir/media"; + sj-mount-siempie = "sshfs nas.siempie.local:/tank/siempie /home/simon/remotedir/siempie"; umount-media = "sudo umount /home/simon/remotedir/media"; umount-siempie = "sudo umount /home/simon/remotedir/siempie"; diff --git a/waybar/spotify.py b/waybar/spotify.py deleted file mode 100644 index 7d80301..0000000 --- a/waybar/spotify.py +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/env python3 -import gi -gi.require_version("Playerctl", "2.0") -from gi.repository import Playerctl, GLib -from gi.repository.Playerctl import Player -import argparse -import logging -import sys -import signal -import gi -import json -import os -from typing import List - -logger = logging.getLogger(__name__) - -def signal_handler(sig, frame): - logger.info("Received signal to stop, exiting") - sys.stdout.write("\n") - sys.stdout.flush() - # loop.quit() - sys.exit(0) - - -class PlayerManager: - def __init__(self, selected_player=None): - self.manager = Playerctl.PlayerManager() - self.loop = GLib.MainLoop() - self.manager.connect( - "name-appeared", lambda *args: self.on_player_appeared(*args)) - self.manager.connect( - "player-vanished", lambda *args: self.on_player_vanished(*args)) - - signal.signal(signal.SIGINT, signal_handler) - signal.signal(signal.SIGTERM, signal_handler) - signal.signal(signal.SIGPIPE, signal.SIG_DFL) - self.selected_player = selected_player - - self.init_players() - - def init_players(self): - for player in self.manager.props.player_names: - if self.selected_player is not None and self.selected_player != player.name: - logger.debug(f"{player.name} is not the filtered player, skipping it") - continue - self.init_player(player) - - def run(self): - logger.info("Starting main loop") - self.loop.run() - - def init_player(self, player): - logger.info(f"Initialize new player: {player.name}") - player = Playerctl.Player.new_from_name(player) - player.connect("playback-status", - self.on_playback_status_changed, None) - player.connect("metadata", self.on_metadata_changed, None) - self.manager.manage_player(player) - self.on_metadata_changed(player, player.props.metadata) - - def get_players(self) -> List[Player]: - return self.manager.props.players - - def write_output(self, text, player): - logger.debug(f"Writing output: {text}") - - output = {"text": text, - "class": "custom-" + player.props.player_name, - "alt": player.props.player_name} - - sys.stdout.write(json.dumps(output) + "\n") - sys.stdout.flush() - - def clear_output(self): - sys.stdout.write("\n") - sys.stdout.flush() - - def on_playback_status_changed(self, player, status, _=None): - logger.debug(f"Playback status changed for player {player.props.player_name}: {status}") - self.on_metadata_changed(player, player.props.metadata) - - def get_first_playing_player(self): - players = self.get_players() - logger.debug(f"Getting first playing player from {len(players)} players") - if len(players) > 0: - # if any are playing, show the first one that is playing - # reverse order, so that the most recently added ones are preferred - for player in players[::-1]: - if player.props.status == "Playing": - return player - # if none are playing, show the first one - return players[0] - else: - logger.debug("No players found") - return None - - def show_most_important_player(self): - logger.debug("Showing most important player") - # show the currently playing player - # or else show the first paused player - # or else show nothing - current_player = self.get_first_playing_player() - if current_player is not None: - self.on_metadata_changed(current_player, current_player.props.metadata) - else: - self.clear_output() - - def on_metadata_changed(self, player, metadata, _=None): - logger.debug(f"Metadata changed for player {player.props.player_name}") - player_name = player.props.player_name - - track_info = "" - if player_name == "spotify" and "mpris:trackid" in metadata.keys() and ":ad:" in player.props.metadata["mpris:trackid"]: - track_info = "Advertisement" - else: - track_info = " " - - if track_info: - if player.props.status == "Playing": - track_info = "▶️" - else: - track_info = "⏸️" - # only print output if no other player is playing - current_playing = self.get_first_playing_player() - if current_playing is None or current_playing.props.player_name == player.props.player_name: - self.write_output(track_info, player) - else: - logger.debug(f"Other player {current_playing.props.player_name} is playing, skipping") - - def on_player_appeared(self, _, player): - logger.info(f"Player has appeared: {player.name}") - if player is not None and (self.selected_player is None or player.name == self.selected_player): - self.init_player(player) - else: - logger.debug( - "New player appeared, but it's not the selected player, skipping") - - def on_player_vanished(self, _, player): - logger.info(f"Player {player.props.player_name} has vanished") - self.show_most_important_player() - -def parse_arguments(): - parser = argparse.ArgumentParser() - - # Increase verbosity with every occurrence of -v - parser.add_argument("-v", "--verbose", action="count", default=0) - - # Define for which player we"re listening - parser.add_argument("--player") - - parser.add_argument("--enable-logging", action="store_true") - - return parser.parse_args() - - -def main(): - arguments = parse_arguments() - - # Initialize logging - if arguments.enable_logging: - logfile = os.path.join(os.path.dirname( - os.path.realpath(__file__)), "media-player.log") - logging.basicConfig(filename=logfile, level=logging.DEBUG, - format="%(asctime)s %(name)s %(levelname)s:%(lineno)d %(message)s") - - # Logging is set by default to WARN and higher. - # With every occurrence of -v it's lowered by one - logger.setLevel(max((3 - arguments.verbose) * 10, 0)) - - logger.info("Creating player manager") - if arguments.player: - logger.info(f"Filtering for player: {arguments.player}") - player = PlayerManager(arguments.player) - player.run() - - -if __name__ == "__main__": - main()