refactor: small changes
This commit is contained in:
parent
749e2cf67d
commit
372ee5985a
4 changed files with 86 additions and 54 deletions
|
@ -34,42 +34,54 @@ let
|
||||||
|
|
||||||
which-nix = pkgs.writeFishApplication {
|
which-nix = pkgs.writeFishApplication {
|
||||||
name = "which-nix";
|
name = "which-nix";
|
||||||
runtimeInputs = with pkgs; [ which coreutils-full ];
|
runtimeInputs = with pkgs; [ which coreutils-full procps ];
|
||||||
text = /* fish */ ''
|
text = /* fish */ ''
|
||||||
readlink -f (which $argv)
|
function recurse -a path;
|
||||||
|
if not test -f "$path"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
echo $path
|
||||||
|
if test -L $path
|
||||||
|
recurse (readlink $path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for arg in $argv
|
||||||
|
recurse (which $arg)
|
||||||
|
end
|
||||||
'';
|
'';
|
||||||
completions = /* fish */ ''
|
completions = /* fish */ ''
|
||||||
complete -c which-nix -fa '(__fish_complete_command)'
|
complete -c which-nix -fa '(__fish_complete_command)'
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
gi = pkgs.writeFishApplication
|
gi = pkgs.writeFishApplication {
|
||||||
{
|
name = "gi";
|
||||||
name = "gi";
|
runtimeInputs = with pkgs; [ fzf gum curl ];
|
||||||
runtimeInputs = with pkgs; [ fzf gum curl ];
|
text = /* fish */ ''
|
||||||
text = /* fish */ ''
|
set url https://www.gitignore.io/api
|
||||||
set url https://www.gitignore.io/api
|
|
||||||
|
|
||||||
if test (count $argv) -eq 0
|
if test (count $argv) -eq 0
|
||||||
set choice ( curl -sL $url/list \
|
set choice ( curl -sL $url/list \
|
||||||
| string split "," \
|
| string split "," \
|
||||||
| fzf -m \
|
| fzf -m \
|
||||||
| string join "," )
|
| string join "," )
|
||||||
else
|
else
|
||||||
set choice (string join "," $argv[1..])
|
set choice (string join "," $argv[1..])
|
||||||
end
|
end
|
||||||
|
|
||||||
if gum confirm "Overwrite current .gitignore?"
|
if gum confirm "Overwrite current .gitignore?"
|
||||||
curl -sL $url/$choice > .gitignore
|
curl -sL $url/$choice > .gitignore
|
||||||
else
|
else
|
||||||
curl -sL $url/$choice >> .gitignore
|
curl -sL $url/$choice >> .gitignore
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
completions = /* fish */ ''
|
completions = /* fish */ ''
|
||||||
set args (curl -sL https://www.gitignore.io/api/list | string split ",")
|
set args (curl -sL https://www.gitignore.io/api/list | string split ",")
|
||||||
complete -c gi -fa "$args"
|
complete -c gi -fa "$args"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
users.users.moritz = {
|
users.users.moritz = {
|
||||||
|
|
|
@ -8,9 +8,12 @@ with lib;
|
||||||
let
|
let
|
||||||
cfg = config.my.programs.fish;
|
cfg = config.my.programs.fish;
|
||||||
shellConfig = config.my.shell;
|
shellConfig = config.my.shell;
|
||||||
exportVariables =
|
exportedVariables =
|
||||||
lib.mapAttrsToList (n: v: ''set -x ${n} "${v}"'') shellConfig.variables;
|
let
|
||||||
exportedVariables = lib.concatStringsSep "\n" exportVariables;
|
exportVariables =
|
||||||
|
lib.mapAttrsToList (n: v: ''set -x ${n} "${v}"'') shellConfig.variables;
|
||||||
|
in
|
||||||
|
lib.concatStringsSep "\n" exportVariables;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.my.programs.fish.enable = mkEnableOption "fish";
|
options.my.programs.fish.enable = mkEnableOption "fish";
|
||||||
|
|
|
@ -17,7 +17,7 @@ in
|
||||||
gateway = "vpn.uni-leipzig.de";
|
gateway = "vpn.uni-leipzig.de";
|
||||||
protocol = "anyconnect";
|
protocol = "anyconnect";
|
||||||
user = "mb18cele@uni-leipzig.de";
|
user = "mb18cele@uni-leipzig.de";
|
||||||
# NOTE file content as follows:
|
# NOTE: file content as follows:
|
||||||
# <my_password>
|
# <my_password>
|
||||||
# "1-Standard-Uni" or "2-Spezial-Alles"
|
# "1-Standard-Uni" or "2-Spezial-Alles"
|
||||||
# Explanation:
|
# Explanation:
|
||||||
|
|
|
@ -2,7 +2,33 @@ _:
|
||||||
|
|
||||||
final: _:
|
final: _:
|
||||||
with final.lib;
|
with final.lib;
|
||||||
{
|
rec {
|
||||||
|
fishFile =
|
||||||
|
{ name
|
||||||
|
, destination
|
||||||
|
, content
|
||||||
|
, checkPhase ? null
|
||||||
|
}:
|
||||||
|
final.writeTextFile {
|
||||||
|
inherit name destination;
|
||||||
|
executable = true;
|
||||||
|
allowSubstitutes = true;
|
||||||
|
preferLocalBuild = false;
|
||||||
|
text = ''
|
||||||
|
#!${getExe final.fish}
|
||||||
|
|
||||||
|
${content}
|
||||||
|
'';
|
||||||
|
|
||||||
|
checkPhase =
|
||||||
|
if checkPhase == null then ''
|
||||||
|
runHook preCheck
|
||||||
|
${getExe final.fish} -n "$target"
|
||||||
|
runHook postCheck
|
||||||
|
''
|
||||||
|
else checkPhase;
|
||||||
|
};
|
||||||
|
|
||||||
writeFishApplication =
|
writeFishApplication =
|
||||||
{ name
|
{ name
|
||||||
, text
|
, text
|
||||||
|
@ -11,30 +37,21 @@ with final.lib;
|
||||||
, checkPhase ? null
|
, checkPhase ? null
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
fishFile = destination: content: final.writeTextFile {
|
runtimeHeader = optionalString (runtimeInputs != [ ])
|
||||||
inherit name destination;
|
''export PATH="${makeBinPath runtimeInputs}:$PATH"'';
|
||||||
executable = true;
|
|
||||||
allowSubstitutes = true;
|
|
||||||
preferLocalBuild = false;
|
|
||||||
text = ''
|
|
||||||
#!${getExe final.fish}
|
|
||||||
|
|
||||||
${optionalString (runtimeInputs != [ ]) ''export PATH="${makeBinPath runtimeInputs}:$PATH"''}
|
script = fishFile {
|
||||||
|
inherit checkPhase;
|
||||||
${content}
|
name = "${name}_script";
|
||||||
'';
|
destination = "/bin/${name}";
|
||||||
|
content = concatLines [ runtimeHeader text ];
|
||||||
checkPhase =
|
};
|
||||||
if checkPhase == null then ''
|
completions_file = fishFile {
|
||||||
runHook preCheck
|
inherit checkPhase;
|
||||||
${getExe final.fish} -n "$target"
|
name = "${name}_completions";
|
||||||
runHook postCheck
|
destination = "/share/fish/vendor_completions.d/${name}.fish";
|
||||||
''
|
content = concatLines [ runtimeHeader completions ];
|
||||||
else checkPhase;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
script = fishFile "/bin/${name}" text;
|
|
||||||
completions_file = fishFile "/share/fish/vendor_completions.d/${name}.fish" completions;
|
|
||||||
in
|
in
|
||||||
final.symlinkJoin {
|
final.symlinkJoin {
|
||||||
inherit name;
|
inherit name;
|
||||||
|
|
Loading…
Reference in a new issue