mirror of
https://github.com/deltathetawastaken/dotfiles.git
synced 2025-12-06 07:16:37 +03:00
fish functions as derivation
This commit is contained in:
parent
499a7e5b38
commit
731e98d56e
12
derivations/fish/fish-functions.nix
Normal file
12
derivations/fish/fish-functions.nix
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{ stdenv, lib, buildFishPlugin }:
|
||||||
|
|
||||||
|
buildFishPlugin rec {
|
||||||
|
pname = "my-fish-functions";
|
||||||
|
version = "1.0.0";
|
||||||
|
|
||||||
|
src = ./fish-functions; # use local directory
|
||||||
|
|
||||||
|
meta = with stdenv.lib; {
|
||||||
|
description = "My custom fish functions";
|
||||||
|
};
|
||||||
|
}
|
||||||
18
derivations/fish/fish-functions/completions/bd.fish
Normal file
18
derivations/fish/fish-functions/completions/bd.fish
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env fish
|
||||||
|
# -*- mode:fish; tab-width:4 -*-
|
||||||
|
#
|
||||||
|
# fish-completion for fish-bd
|
||||||
|
# https://github.com/0rax/fish-bd
|
||||||
|
#
|
||||||
|
|
||||||
|
complete -c bd -s c --description "Classic mode : goes back to the first directory named as the string"
|
||||||
|
complete -c bd -s s --description "Seems mode : goes back to the first directory containing string"
|
||||||
|
complete -c bd -s i --description "Case insensitive move (implies seems mode)"
|
||||||
|
complete -c bd -s h -x --description "Display help and exit"
|
||||||
|
complete -c bd -A -f
|
||||||
|
|
||||||
|
function __fish_bd_complete_dirs
|
||||||
|
printf (pwd | sed 's%/[^/]*$%/%; s/.$//; s|/|\\\n|g')
|
||||||
|
end
|
||||||
|
|
||||||
|
complete -c bd -a '(__fish_bd_complete_dirs)'
|
||||||
96
derivations/fish/fish-functions/functions/bd.fish
Normal file
96
derivations/fish/fish-functions/functions/bd.fish
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
#!/usr/bin/env fish
|
||||||
|
# -*- mode:fish; tab-width:4 -*-
|
||||||
|
#
|
||||||
|
# fish-bd main & usage function
|
||||||
|
# https://github.com/0rax/bd-fish
|
||||||
|
#
|
||||||
|
|
||||||
|
function bd
|
||||||
|
|
||||||
|
set -l oldpwd (pwd)
|
||||||
|
set -l newpwd ""
|
||||||
|
set -l opts "$BD_OPT"
|
||||||
|
set -l args (getopt "csih" $argv)
|
||||||
|
|
||||||
|
if [ $status -gt 0 ]
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
set args (echo $args | sed 's/^\s//' | tr ' ' '\n')
|
||||||
|
|
||||||
|
set -l i 1
|
||||||
|
for arg in $args
|
||||||
|
switch $arg
|
||||||
|
case "-h"
|
||||||
|
printf "# fish-bd v1.3.3 (https://github.com/0rax/bd-fish)
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Quickly go back to a parent directory up in your current working directory tree.
|
||||||
|
Don't write 'cd ../../..' redundantly, use bd instead.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
bd [option] <pattern>
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
# You are in /home/user/my/path/is/very/long/
|
||||||
|
# And you want to go back to 'path', simple type
|
||||||
|
> bd path
|
||||||
|
# or
|
||||||
|
> bd -s pa
|
||||||
|
# or
|
||||||
|
> bd -i Pat
|
||||||
|
# And you are now in /home/user/my/path/
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-c <pattern>
|
||||||
|
Classic mode : goes back to the first directory matching the pattern (default)
|
||||||
|
Set if default using (set -gx BD_OPT 'classic')
|
||||||
|
Default mode when BD_OPT or CLI options are specified
|
||||||
|
-s <pattern>
|
||||||
|
Seems mode: goes back to the first directory starting with pattern
|
||||||
|
Set it as default using (set -gx BD_OPT 'sensitive')
|
||||||
|
-i <pattern>
|
||||||
|
Case insensitive mode: same as seems mode without case sensitity
|
||||||
|
Set it as default using (set -gx BD_OPT 'insensitive')
|
||||||
|
-h Print this help and exit
|
||||||
|
|
||||||
|
Note:
|
||||||
|
Fuzzy matching of a directory can be done with any mode using the built-in
|
||||||
|
fish-shell autocompletion. This allows you to enter any part of the path
|
||||||
|
and still match it.\n"
|
||||||
|
return 0
|
||||||
|
case "-s"
|
||||||
|
set opts "sensitive"
|
||||||
|
case "-i"
|
||||||
|
set opts "insensitive"
|
||||||
|
case "-c"
|
||||||
|
set opts "classic"
|
||||||
|
case "--"
|
||||||
|
set i (math $i + 1)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
set i (math $i + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
if [ $i -gt (count $args) ]
|
||||||
|
cd ..
|
||||||
|
pwd
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
switch "$opts"
|
||||||
|
case "sensitive"
|
||||||
|
set newpwd (echo $oldpwd | sed 's|\(.*/'$args[$i]'[^/]*/\).*|\1|')
|
||||||
|
case "insensitive"
|
||||||
|
set newpwd (echo $oldpwd | perl -pe 's|(.*/'$args[$i]'[^/]*/).*|$1|i')
|
||||||
|
case '*' # classic
|
||||||
|
set newpwd (echo $oldpwd | sed 's|\(.*/'$args[$i]'/\).*|\1|')
|
||||||
|
end
|
||||||
|
|
||||||
|
if [ "$newpwd" = "$oldpwd" ]
|
||||||
|
echo "No such occurence." >&2
|
||||||
|
else
|
||||||
|
echo "$newpwd"
|
||||||
|
cd "$newpwd"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
5
derivations/fish/fish-functions/functions/icat_auto.fish
Normal file
5
derivations/fish/fish-functions/functions/icat_auto.fish
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
function icat_auto
|
||||||
|
set cols (math (tput cols) - 1)
|
||||||
|
set lines (math (tput lines) - 1)
|
||||||
|
kitty +kitten icat --place $cols"x"$lines"@0x0" $argv
|
||||||
|
end
|
||||||
12
derivations/fish/fish-functions/functions/up.fish
Normal file
12
derivations/fish/fish-functions/functions/up.fish
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
function up
|
||||||
|
if test -z "$argv"
|
||||||
|
cd ..
|
||||||
|
else
|
||||||
|
switch $argv
|
||||||
|
case '*'
|
||||||
|
for i in (seq $argv)
|
||||||
|
cd ..
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue