nixos-config/home-manager/modules/fish/functions.nix

106 lines
3.2 KiB
Nix
Raw Normal View History

{ pkgs, ... }:
2024-02-05 11:46:52 +01:00
{
# Mark each prompt so you can jump between prompts with C-S-z and C-S-x
mark_prompt_start = {
onEvent = "fish_prompt";
body = ''
${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 = {
body = ''
history --save
set -gx dirprev $dirprev
set -gx dirnext $dirnext
set -gx dirstack $dirstack
set -g fish_greeting ""
exec fish
'';
description = "Reload Fish while keeping some context";
};
update-env = {
body = ''
set -gx SWAYSOCK /run/user/(id -u)/sway-ipc.(id -u).(pgrep -x sway).sock
'';
description = "Update environment variables";
};
clangfmt = {
body = ''
set source_exts "h" "hpp" "c" "cpp" "cc" "cp" "c++" "cxx" "cu" "proto"
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 (${pkgs.coreutils}/bin/realpath $repo_path/$f)
${pkgs.coreutils}/bin/echo "Processing $file"
2022-03-01 22:19:03 +01:00
set ext (string match -r ".*\.([^\.]+)\$" $file)[2]
if contains $ext $source_exts
${pkgs.coreutils}/bin/echo "Formatting $file"
$clangformat -i -style=file $file
else
${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 = ''
2024-04-25 13:01:28 +02:00
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
2024-04-15 16:29:31 +02:00
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
set libcomponents (string split "." "$lib")
set libname $libcomponents[1].$libcomponents[2]
set libmajor $libname.$libcomponents[3]
if test -f $libname -o -L $libname
${pkgs.coreutils}/bin/echo "$libname already exists"
return 1
end
if test -f $libmajor -o -L $libmajor
${pkgs.coreutils}/bin/echo "$libmajor already exists"
return 2
end
${pkgs.coreutils}/bin/ln -s $lib $libmajor
${pkgs.coreutils}/bin/ln -s $libmajor $libname
end
'';
};
}