diff --git a/home-manager/modules/fish/default.nix b/home-manager/modules/fish/default.nix index 3f710dd..7da3e4e 100644 --- a/home-manager/modules/fish/default.nix +++ b/home-manager/modules/fish/default.nix @@ -24,7 +24,7 @@ in programs = { fish = { enable = true; - functions = import ./functions.nix { inherit (pkgs) git coreutils; }; + functions = import ./functions.nix { inherit pkgs; }; plugins = [ { diff --git a/home-manager/modules/fish/functions.nix b/home-manager/modules/fish/functions.nix index 24b1812..074b9b1 100644 --- a/home-manager/modules/fish/functions.nix +++ b/home-manager/modules/fish/functions.nix @@ -1,9 +1,24 @@ -{ git, coreutils }: +{ pkgs, ... }: { + # Mark each prompt so you can jump between prompts with C-S-z and C-S-x mark_prompt_start = { onEvent = "fish_prompt"; body = '' - ${coreutils}/bin/echo -en "\e]133;A\e\\" + ${pkgs.coreutils}/bin/echo -en "\e]133;A\e\\" + ''; + }; + # Mark the start and end of the output of a command + # This + foot_cmd_start = { + onEvent = "fish_preexec"; + body = '' + ${pkgs.coreutils}/bin/echo -en "\e]133;C\e\\" + ''; + }; + foot_cmd_end = { + onEvent = "fish_postexec"; + body = '' + ${pkgs.coreutils}/bin/echo -en "\e]133;D\e\\" ''; }; reload = { @@ -26,28 +41,45 @@ clangfmt = { body = '' set source_exts "h" "hpp" "c" "cpp" "cc" "cp" "c++" "cxx" "cu" "proto" - set files (${git}/bin/git diff --diff-filter=ACMR --name-only $argv[1]) - set repo_path (realpath --relative-to=$PWD (${git}/bin/git rev-parse --show-toplevel)) - set clangformat (${git}/bin/git config --get clangFormat.binary) - ${coreutils}/bin/echo "Formatting files in $repo_path with $clangformat" + set files (${pkgs.git}/bin/git diff --diff-filter=ACMR --name-only $argv[1]) + set repo_path (${pkgs.coreutils}/bin/realpath --relative-to=$PWD (${pkgs.git}/bin/git rev-parse --show-toplevel)) + set clangformat (${pkgs.git}/bin/git config --get clangFormat.binary) + ${pkgs.coreutils}/bin/echo "Formatting files in $repo_path with $clangformat" for f in $files - set file (realpath $repo_path/$f) - ${coreutils}/bin/echo "Processing $file" + set file (${pkgs.coreutils}/bin/realpath $repo_path/$f) + ${pkgs.coreutils}/bin/echo "Processing $file" set ext (string match -r ".*\.([^\.]+)\$" $file)[2] if contains $ext $source_exts - ${coreutils}/bin/echo "Formatting $file" + ${pkgs.coreutils}/bin/echo "Formatting $file" $clangformat -i -style=file $file else - ${coreutils}/bin/echo "Extension $ext not found in $source_exts" + ${pkgs.coreutils}/bin/echo "Extension $ext not found in $source_exts" end end ''; description = "Use clang-format to format all changed and added files"; }; + kink = { + body = '' + set -f pls_url = "https://playerservices.streamtheworld.com/pls/KINKAAC.pls" + if [ "$channel" = "dna" ] + set pls_url "https://playerservices.streamtheworld.com/pls/KINK_DNAAAC.pls" + else if [ "$channel" = "distortion" ] + set pls_url "https://playerservices.streamtheworld.com/pls/KINK_DISTORTIONAAC.pls" + end + set -f stream_url (${pkgs.curl}/bin/curl -sSL $pls_url | grep File | shuf | head -n 1 | awk -F '=' 'BEGIN { RS="\r\n" } { print $2 }') + mpc clear + mpc add "$stream_url" + mpc play + ''; + argumentNames = "channel"; + description = "Play a KINK channel with mpc"; + }; + linklib = { body = '' function linklib --argument lib @@ -56,17 +88,17 @@ set libmajor $libname.$libcomponents[3] if test -f $libname -o -L $libname - ${coreutils}/bin/echo "$libname already exists" + ${pkgs.coreutils}/bin/echo "$libname already exists" return 1 end if test -f $libmajor -o -L $libmajor - ${coreutils}/bin/echo "$libmajor already exists" + ${pkgs.coreutils}/bin/echo "$libmajor already exists" return 2 end - ${coreutils}/bin/ln -s $lib $libmajor - ${coreutils}/bin/ln -s $libmajor $libname + ${pkgs.coreutils}/bin/ln -s $lib $libmajor + ${pkgs.coreutils}/bin/ln -s $libmajor $libname end ''; };