feat: initial commit; NixOS Era
This commit is contained in:
15
pkgs/fish/config.fish
Normal file
15
pkgs/fish/config.fish
Normal file
@@ -0,0 +1,15 @@
|
||||
set fish_greeting '( .-.)'
|
||||
|
||||
fish_vi_key_bindings
|
||||
|
||||
alias cls='clear; and echo $fish_greeting';
|
||||
alias ...='cd ../..';
|
||||
|
||||
set -l directory (status dirname)
|
||||
|
||||
[ -f "$directory/prompt.fish" ]; and source "$directory/prompt.fish"
|
||||
[ -f "$directory/alias.fish" ]; and source "$directory/alias.fish"
|
||||
|
||||
if not set -qx SSH_AUTH_SOCK
|
||||
set -x SSH_AUTH_SOCK (gpgconf --list-dirs agent-ssh-socket)
|
||||
end
|
||||
23
pkgs/fish/default.nix
Normal file
23
pkgs/fish/default.nix
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
lib ? pkgs.lib,
|
||||
...
|
||||
}:
|
||||
|
||||
pkgs.stdenv.mkDerivation rec {
|
||||
pname = "fish-config";
|
||||
version = "1.0";
|
||||
|
||||
src = builtins.path {
|
||||
path = ./.;
|
||||
name = pname;
|
||||
};
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
cp -r ${src}/* $out/
|
||||
'';
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
}
|
||||
26
pkgs/fish/functions/clip.fish
Normal file
26
pkgs/fish/functions/clip.fish
Normal file
@@ -0,0 +1,26 @@
|
||||
function clip
|
||||
if not command -q xclip
|
||||
echoerr "clip: 'xclip' is not available on this system"
|
||||
return 1
|
||||
end
|
||||
|
||||
if not tty -s
|
||||
set -l stdin
|
||||
read stdin -z
|
||||
end
|
||||
|
||||
if set -ql stdin
|
||||
echo "$stdin" | xclip -selection clipboard
|
||||
echo "copied into clipboard (stdin)"
|
||||
return 0
|
||||
end
|
||||
|
||||
if [ -n "$(string trim -- $argv)" ]
|
||||
echo "$argv" | xclip -selection clipboard
|
||||
echo "copied into clipboard"
|
||||
return 0
|
||||
end
|
||||
|
||||
xclip -selection clipboard -o
|
||||
end
|
||||
|
||||
3
pkgs/fish/functions/echoerr.fish
Normal file
3
pkgs/fish/functions/echoerr.fish
Normal file
@@ -0,0 +1,3 @@
|
||||
function echoerr
|
||||
echo $argv >&2
|
||||
end
|
||||
45
pkgs/fish/functions/nix-shell.fish
Normal file
45
pkgs/fish/functions/nix-shell.fish
Normal file
@@ -0,0 +1,45 @@
|
||||
function nix-shell
|
||||
set -l _argv (string split ' ' -- $argv);
|
||||
|
||||
if contains -- '-q' $_argv; or contains -- '--query' $_argv
|
||||
for pkg in (string split ' ' -- $FISH_NIX_PACKAGES)
|
||||
echo $pkg
|
||||
end
|
||||
return 0;
|
||||
end
|
||||
|
||||
function package_flag -a arg
|
||||
contains -- '-p' $arg
|
||||
or contains -- '--packages' $arg
|
||||
end
|
||||
|
||||
if not command -q nix-shell; or not package_flag $argv
|
||||
command nix-shell --run fish $argv;
|
||||
return $status;
|
||||
end
|
||||
|
||||
set -l packages
|
||||
set -l reading_packages 0
|
||||
for arg in $_argv
|
||||
if [ $reading_packages -ne 0 ]
|
||||
if string match -r '^-'
|
||||
set reading_packages 0
|
||||
else
|
||||
not contains -- $arg (string split ' ' -- $FISH_NIX_PACKAGES);
|
||||
and set packages $packages $arg
|
||||
end
|
||||
else
|
||||
package_flag $arg; and set reading_packages 1
|
||||
end
|
||||
end
|
||||
|
||||
set -l prev_packages $FISH_NIX_PACKAGES;
|
||||
set -x FISH_NIX_PACKAGES $prev_packages $packages;
|
||||
|
||||
command nix-shell --run fish $argv;
|
||||
set -l nix_status $status;
|
||||
|
||||
set -x FISH_NIX_PACKAGES $prev_packages;
|
||||
|
||||
return $nix_status
|
||||
end
|
||||
12
pkgs/fish/functions/nix-shell.fish.bckup
Normal file
12
pkgs/fish/functions/nix-shell.fish.bckup
Normal file
@@ -0,0 +1,12 @@
|
||||
function nix-shell
|
||||
if not command -q nix-shell
|
||||
command nix-shell;
|
||||
return $status;
|
||||
end
|
||||
|
||||
set -l _argv $argv
|
||||
argparse -i 'p/packages=' -- $argv
|
||||
or command nix-shell -- $_argv
|
||||
|
||||
set -x FISH_NIX_PACKAGES
|
||||
end
|
||||
18
pkgs/fish/functions/round.fish
Normal file
18
pkgs/fish/functions/round.fish
Normal file
@@ -0,0 +1,18 @@
|
||||
function round
|
||||
argparse -n 'round' -i 'p/precision=!_validate_int' -- $argv
|
||||
or return 1;
|
||||
|
||||
set -l value (string trim -- $argv)
|
||||
if [ -z $value ]
|
||||
echoerr 'round: no input'
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l precision 1
|
||||
if set -q _flag_precision
|
||||
set precision (math "10 ^ $_flag_precision")
|
||||
end
|
||||
|
||||
set value (math "$value * $precision")
|
||||
echo (math "round($value) / $precision")
|
||||
end
|
||||
76
pkgs/fish/prompt.fish
Normal file
76
pkgs/fish/prompt.fish
Normal file
@@ -0,0 +1,76 @@
|
||||
function fish_mode_prompt; end
|
||||
|
||||
function fish_prompt
|
||||
set -l command_status $status;
|
||||
|
||||
set -l duration '';
|
||||
begin
|
||||
[ $CMD_DURATION -gt 700 ]; and set -l seconds \
|
||||
"$(round -p 2 (math $CMD_DURATION / 1000 % 60))s";
|
||||
[ $CMD_DURATION -gt 60000 ]; and set -l minutes \
|
||||
"$(round (math $CMD_DURATION / 60000))m";
|
||||
|
||||
[ $CMD_DURATION -gt 700 ]; and set duration (string join '' -- \
|
||||
(set_color normal) \
|
||||
'took ' \
|
||||
(set_color yellow) \
|
||||
(string join ' ' -- $minutes $seconds) \
|
||||
);
|
||||
end
|
||||
|
||||
set -l mode
|
||||
begin
|
||||
function color_and_wrap -a color char
|
||||
string join '' -- (set_color --bold $color) "[$char]"
|
||||
functions -e color_and_wrap
|
||||
end
|
||||
|
||||
set -l indicator \
|
||||
(switch $fish_bind_mode
|
||||
case default; color_and_wrap red 'N'
|
||||
case insert; color_and_wrap cyan 'I'
|
||||
case replace_one; color_and_wrap green 'R'
|
||||
case visual; color_and_wrap brmagenta 'V'
|
||||
case '*'; color_and_wrap red '?'
|
||||
end)
|
||||
set mode (string join '' -- $indicator (set_color normal) ' ')
|
||||
end
|
||||
|
||||
set -l nix_shell
|
||||
begin
|
||||
set -l packages (string split ' ' -- $FISH_NIX_PACKAGES)
|
||||
|
||||
if [ -n "$IN_NIX_SHELL" ]
|
||||
set nix_shell "$(set_color brblue) "
|
||||
|
||||
set -ql packages[1]; and set nix_shell "$nix_shell($packages[1]";
|
||||
set -ql packages[2]; and set nix_shell "$nix_shell, $packages[2]";
|
||||
set -ql packages[3]; and not set -ql packages[4]; and set nix_shell "$nix_shell, $packages[3]";
|
||||
|
||||
set -ql packages[4]; and set nix_shell "$nix_shell, +$(math (count $packages) - 2) more"
|
||||
|
||||
set -ql packages[1]; set nix_shell "$nix_shell) "
|
||||
end
|
||||
end
|
||||
|
||||
set -l cursor_color (set_color green)
|
||||
[ $command_status -ne 0 ]; and set -l cursor_color (set_color red)
|
||||
|
||||
set -l pwd (string join '' -- \
|
||||
$cursor_color \
|
||||
(prompt_pwd -D 2 -d 1) \
|
||||
(set_color normal) \
|
||||
);
|
||||
|
||||
[ (fish_vcs_prompt) ]; and set -l git (string join '' -- \
|
||||
(set_color yellow) \
|
||||
' ' \
|
||||
(string sub -s 3 -e -1 -- (fish_vcs_prompt)) \
|
||||
' ' \
|
||||
);
|
||||
|
||||
[ $command_status -ne 0 ]; and set -l last_status "[$command_status]";
|
||||
|
||||
[ -n $duration ]; and echo $duration
|
||||
string join '' -- $mode $nix_shell $pwd $git $cursor_color $last_status '|> '
|
||||
end
|
||||
Reference in New Issue
Block a user