fish: Updated functions

- Added the KINK play function
- Added pre- and post-exec event handlers for pipe-command-output
- Just add pkgs as argument instead of individual packages
This commit is contained in:
Erwin Boskma 2024-04-12 08:45:28 +02:00
parent ac7c2145b6
commit 2d7d48a13e
Signed by: erwin
SSH key fingerprint: SHA256:3F6Cm6I3erRqlBwEghZWAQl6eS5WrGTX1Vs/Evec1lQ
2 changed files with 47 additions and 15 deletions

View file

@ -24,7 +24,7 @@ in
programs = { programs = {
fish = { fish = {
enable = true; enable = true;
functions = import ./functions.nix { inherit (pkgs) git coreutils; }; functions = import ./functions.nix { inherit pkgs; };
plugins = [ plugins = [
{ {

View file

@ -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 = { mark_prompt_start = {
onEvent = "fish_prompt"; onEvent = "fish_prompt";
body = '' 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 = { reload = {
@ -26,28 +41,45 @@
clangfmt = { clangfmt = {
body = '' body = ''
set source_exts "h" "hpp" "c" "cpp" "cc" "cp" "c++" "cxx" "cu" "proto" 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 files (${pkgs.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 repo_path (${pkgs.coreutils}/bin/realpath --relative-to=$PWD (${pkgs.git}/bin/git rev-parse --show-toplevel))
set clangformat (${git}/bin/git config --get clangFormat.binary) set clangformat (${pkgs.git}/bin/git config --get clangFormat.binary)
${coreutils}/bin/echo "Formatting files in $repo_path with $clangformat" ${pkgs.coreutils}/bin/echo "Formatting files in $repo_path with $clangformat"
for f in $files for f in $files
set file (realpath $repo_path/$f) set file (${pkgs.coreutils}/bin/realpath $repo_path/$f)
${coreutils}/bin/echo "Processing $file" ${pkgs.coreutils}/bin/echo "Processing $file"
set ext (string match -r ".*\.([^\.]+)\$" $file)[2] set ext (string match -r ".*\.([^\.]+)\$" $file)[2]
if contains $ext $source_exts if contains $ext $source_exts
${coreutils}/bin/echo "Formatting $file" ${pkgs.coreutils}/bin/echo "Formatting $file"
$clangformat -i -style=file $file $clangformat -i -style=file $file
else else
${coreutils}/bin/echo "Extension $ext not found in $source_exts" ${pkgs.coreutils}/bin/echo "Extension $ext not found in $source_exts"
end end
end end
''; '';
description = "Use clang-format to format all changed and added files"; 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 = { linklib = {
body = '' body = ''
function linklib --argument lib function linklib --argument lib
@ -56,17 +88,17 @@
set libmajor $libname.$libcomponents[3] set libmajor $libname.$libcomponents[3]
if test -f $libname -o -L $libname if test -f $libname -o -L $libname
${coreutils}/bin/echo "$libname already exists" ${pkgs.coreutils}/bin/echo "$libname already exists"
return 1 return 1
end end
if test -f $libmajor -o -L $libmajor if test -f $libmajor -o -L $libmajor
${coreutils}/bin/echo "$libmajor already exists" ${pkgs.coreutils}/bin/echo "$libmajor already exists"
return 2 return 2
end end
${coreutils}/bin/ln -s $lib $libmajor ${pkgs.coreutils}/bin/ln -s $lib $libmajor
${coreutils}/bin/ln -s $libmajor $libname ${pkgs.coreutils}/bin/ln -s $libmajor $libname
end end
''; '';
}; };