libkookie: base: init module with shell tools, git, and fish support

wip/yesman
Katharina Fey 3 years ago
parent e39465caf3
commit d0b1a2d3e9
  1. 8
      infra/libkookie/configuration/base/default.nix
  2. 6
      infra/libkookie/configuration/base/fish/default.nix
  3. 10
      infra/libkookie/configuration/base/git/default.nix
  4. 34
      infra/libkookie/configuration/base/shell/default.nix
  5. 7
      infra/libkookie/modules/base/default.nix
  6. 10
      infra/libkookie/modules/base/fish/core/alias.fish
  7. 1
      infra/libkookie/modules/base/fish/core/binds.fish
  8. 22
      infra/libkookie/modules/base/fish/core/config.fish
  9. 31
      infra/libkookie/modules/base/fish/core/config.nix
  10. 7
      infra/libkookie/modules/base/fish/core/default.nix
  11. 5
      infra/libkookie/modules/base/fish/core/functions/__fancy_history.fish
  12. 8
      infra/libkookie/modules/base/fish/core/functions/__history_previous_command.fish
  13. 9
      infra/libkookie/modules/base/fish/core/functions/__history_previous_command_arguments.fish
  14. 28
      infra/libkookie/modules/base/fish/core/functions/__kakoune.fish
  15. 6
      infra/libkookie/modules/base/fish/core/functions/__skim_cd.fish
  16. 12
      infra/libkookie/modules/base/fish/core/functions/e.fish
  17. 34
      infra/libkookie/modules/base/fish/core/functions/fish_prompt.fish
  18. 1
      infra/libkookie/modules/base/fish/core/functions/fish_right_prompt.fish
  19. 6
      infra/libkookie/modules/base/fish/core/functions/fish_user_key_bindings.fish
  20. 24
      infra/libkookie/modules/base/fish/core/functions/gen-shell.fish
  21. 18
      infra/libkookie/modules/base/fish/core/functions/k.fish
  22. 7
      infra/libkookie/modules/base/fish/core/functions/nrepl.fish
  23. 12
      infra/libkookie/modules/base/fish/core/functions/nxs.fish
  24. 3
      infra/libkookie/modules/base/fish/core/functions/restart.fish
  25. 40
      infra/libkookie/modules/base/fish/core/functions/rvm.fish
  26. 4
      infra/libkookie/modules/base/fish/core/functions/search.fish
  27. 12
      infra/libkookie/modules/base/fish/core/setup.nix
  28. 12
      infra/libkookie/modules/base/fish/default.nix
  29. 9
      infra/libkookie/modules/base/fish/hm.nix
  30. 1
      infra/libkookie/modules/default.nix

@ -0,0 +1,8 @@
/**
* A set of userspace tools to install for all systems
*/
{ config, lib, pkgs, ... }:
{
imports = [ ./fish ./git ./shell ]
}

@ -0,0 +1,6 @@
{ config, pkgs, ... }:
{
imports = [ <modules/base/fish/hm.nix> ];
libkookie.base.fish.enable = true;
}

@ -0,0 +1,10 @@
{ config, pkgs, ... }:
let
git = (pkgs.git.override { svnSupport = true; sendEmailSupport = true; });
in
{
environment.systemPackages = [ git ] ++
(with pkgs.gitAndTools;
[ hub git-remote-hg ]);
}

@ -0,0 +1,34 @@
/* ADDITIONAL SHELL TOOLS
*
* This module is a bit hard to wrap your head around, not because of
* what it does but because of the classification of tools it
* contains. It's a list of various utilities that are super useful
* for day-to-day use, but it's difficult to avoid just having one
* large file that contains _all_ applications you would ever use.
*
* Only add stuff to this list if you're sure that it will be useful
* on ALL workstations, as well as root-servers and user-servers!
*/
{ pkgs, ... }:
{
home-manager.users.spacekookie = { ... }: {
home.packages = with pkgs; [
bat
curl
fzf
htop
kakoune # used to have a vim-type editor everywhere
moreutils
pciutils
pv
ripgrep
skim
tmux
tree
usbutils
wget
];
};
}

@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./fish
];
}

@ -0,0 +1,10 @@
# Useful
alias todo="void /home/.local/todo.db"
alias debug="env RUST_BACKTRACE=1 fish -c"
alias stalk="watch -n 0.1"
alias hib="systemctl hibernate"
alias c="cargo"
alias e="emacs"
alias em="emacs (fzf --height=15 --reverse)"
alias skcd="cd (sk ~)"

@ -0,0 +1,22 @@
# source $HOME/.cargo/env
# set -gx PATH $HOME/.cargo/bin $PATH
# The o bit is a bit of a hack
# umask u=rw,g=rw,o-rwx
# direnv hook fish | source
# gnome-keyring insists on setting this to itself, even if ssh support is disabled
set -x SSH_AUTH_SOCK "/run/user/1000/gnupg/S.gpg-agent.ssh"
# Fix some utf-8 errors
set -x LC_ALL en_GB.utf8
# Better nix-shell support!
any-nix-shell fish --info-right | source
# Make git use emacs
set -x EDITOR kak
# tuuuuuuuurbofish!
set fish_greeting 'Welcome to the '(set_color FF66CC)'::<>' (set_color normal)'...'

@ -0,0 +1,31 @@
{ pkgs, ... }:
with pkgs;
with builtins;
''
set fish_function_path ${fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
${readFile ./functions/__fancy_history.fish }
${readFile ./config.fish }
${readFile ./alias.fish }
${readFile ./functions/fish_prompt.fish }
${readFile ./functions/fish_right_prompt.fish }
${readFile ./functions/fish_user_key_bindings.fish }
${readFile ./functions/gen-shell.fish }
${readFile ./functions/__history_previous_command_arguments.fish }
${readFile ./functions/__history_previous_command.fish }
${readFile ./functions/__kakoune.fish }
${readFile ./functions/e.fish }
${readFile ./functions/k.fish }
${readFile ./functions/nrepl.fish }
${readFile ./functions/nxs.fish }
${readFile ./functions/restart.fish }
${readFile ./functions/rvm.fish }
${readFile ./functions/search.fish }
${readFile ./functions/__skim_cd.fish }
${readFile ./binds.fish}
''

@ -0,0 +1,7 @@
{ config, lib, ... }:
{
# TODO: there's a problem with the fish "command-not-found" db that
# makes it print a weird error
programs.fish.enable = true;
}

@ -0,0 +1,5 @@
function __fancy_history --description "history(1) but cool!"
set __queried_cmd (history | fzf --height=15 --reverse)
commandline -t $__queried_cmd
commandline -f repaint
end

@ -0,0 +1,8 @@
function __history_previous_command
switch (commandline -t)
case "!"
commandline -t $history[1]; commandline -f repaint
case "*"
commandline -i !
end
end

@ -0,0 +1,9 @@
function __history_previous_command_arguments
switch (commandline -t)
case "!"
commandline -t ""
commandline -f history-token-search-backward
case "*"
commandline -i '$'
end
end

@ -0,0 +1,28 @@
function __kakoune --description "Wrapper around starting and re-attaching to kakoune sessions"
set server_name (basename (pwd) | sed 's/\./-/g')
set socket_file (kak -l | grep $server_name)
set seek_point $argv[1]
if test -n ! $seek_point
return 130
end
if test -z $socket_file
kak -d -s $server_name
end
kak -e "edit $seek_point" -c $server_name
end
function __kakoune_get_file_list --description "Get list of files to consider for fzf"
git status ^ /dev/null > /dev/null
if test $status -eq 0
git ls-files -oc --exclude-standard
else
find .
end
end
function __kakoune_get_folder_list --description "Get list of folder to consider for fzf"
find . -type d
end

@ -0,0 +1,6 @@
function __skim_cd --description "run fzf to find a directory to `cd` into"
set directory (find . -type d | fzf --reverse --height=15)
if test $status -eq 0
cd $directory
end
end

@ -0,0 +1,12 @@
# Spawn an emacs daemon for a project directory
function e --description='Setup emacs server and open emacsclient'
set session (basename (pwd))
ps x | grep emacs | grep $session > /dev/null
if test $status != 0
emacs --daemon=$session
end
emacsclient -c -s $session --eval '(fzf)' ^ /dev/null > /dev/null &
end

@ -0,0 +1,34 @@
function fish_prompt --description 'Write out the prompt'
# Save our status
set -l last_status $status
set -l last_status_string ""
if [ $last_status -ne 0 ]
printf "%s(%d)%s " (set_color red --bold) $last_status (set_color normal)
end
if not set -q __hostname
set -g __hostname (hostname|cut -d . -f 1)
end
set -l color_cwd
set -l suffix
set -l CLOSEBRAC ]
set -l OPENBRAC [
switch $USER
case root toor
if set -q fish_color_cwd_root
set color_cwd $fish_color_cwd_root
else
set color_cwd $fish_color_cwd
end
set suffix '#'
case '*'
set color_cwd $fish_color_cwd
set suffix '>'
end
echo -n -s (set_color FF66CC) ' ❤ ' (set_color normal) '(' "$__hostname" ') ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
# echo -n -s (set_color FF66CC) ' I love you Kookie <3 Alyssa ' (set_color normal) '(' "$__hostname" ') ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
end

@ -0,0 +1,6 @@
function fish_user_key_bindings
# Make `!!` and `!$` work
bind ! __history_previous_command
bind '$' __history_previous_command_arguments
bind \cr __fancy_history
end

@ -0,0 +1,24 @@
function gen-shell
if not test $argv[1]
echo "Usage: gen-shell <name>"
return 1
end
if test -e shell.nix
echo "Refusing to override existing `shell.nix`!"
return 1
end
echo 'eval "$(lorri direnv)"' > .envrc
set name $argv[1]
echo "with import <nixpkgs> {};
stdenv.mkDerivation {
name = \"$name\";
buildInputs = with pkgs; [
# Hier könnte Ihre Werbung stehen
];
}" > shell.nix
bat default.nix
end

@ -0,0 +1,18 @@
# Spawn a kak daemon in a project directory and fuzzy open a file
function k --description='Open kakoune via fzf'
# Select a file with `fzf`
set file (__kakoune_get_file_list | fzf --height=25 --reverse)
# Open the file
__kakoune $file
end
function ksm --description "Open a file at an exact line of code"
set file (sk --ansi -c 'rg --color=always --line-number "{}"')
set entry (echo $file | sed 's/\(\:[0-9]*\).*/\1/' | tr ':' ' ')
echo $entry
# Then open the file!
__kakoune $entry
end

@ -0,0 +1,7 @@
function nrepl
if test $argv[1]
nix repl $argv
else
nix repl '<nixpkgs>'
end
end

@ -0,0 +1,12 @@
function nxs
if test $argv[1]
nix run -f '<nixpkgs>' $argv
else
if test -e default.nix
nix-shell
else
echo "No `default.nix`"
return 1
end
end
end

@ -0,0 +1,3 @@
function restart
clear; exec fish
end

@ -0,0 +1,40 @@
function rvm --description='Ruby enVironment Manager'
# run RVM and capture the resulting environment
set --local env_file (mktemp -t rvm.fish.XXXXXXXXXX)
# This finds where RVM's root directory is and sources scripts/rvm from within it. Then loads RVM in a clean environment and dumps the environment variables it generates out for us to use.
bash -c 'PATH=$GEM_HOME/bin:$PATH;RVMA=$(which rvm);RVMB=$(whereis rvm | sed "s/rvm://");source $(if test $RVMA;then echo $RVMA | sed "s/\/bin\//\/scripts\//";elif test $RVMB; then echo $RVMB | sed "s/rvm/rvm\/scripts\/rvm/"; else echo ~/.rvm/scripts/rvm; fi); rvm "$@"; status=$?; env > "$0"; exit $status' $env_file $argv
# apply rvm_* and *PATH variables from the captured environment
and eval (grep -E '^rvm|^PATH|^GEM_PATH|^GEM_HOME' $env_file | grep -v '_clr=' | sed '/^[^=]*PATH/s/:/" "/g; s/^/set -xg /; s/=/ "/; s/$/" ;/; s/(//; s/)//')
# needed under fish >= 2.2.0
and set -xg GEM_PATH (echo $GEM_PATH | sed 's/ /:/g')
# clean up
rm -f $env_file
end
function __handle_rvmrc_stuff --on-variable PWD
# Source a .rvmrc file in a directory after changing to it, if it exists.
# To disable this feature, set rvm_project_rvmrc=0 in $HOME/.rvmrc
if test "$rvm_project_rvmrc" != 0
set -l cwd $PWD
while true
if contains $cwd "" $HOME "/"
if test "$rvm_project_rvmrc_default" = 1
rvm default 1>/dev/null 2>&1
end
break
else
if test -e .rvmrc -o -e .ruby-version -o -e .ruby-gemset
eval "rvm reload" > /dev/null
eval "rvm rvmrc load" >/dev/null
break
else
set cwd (dirname "$cwd")
end
end
end
set -e cwd
end
end

@ -0,0 +1,4 @@
function search --description "Finding some code with sk(1) and rg(1)"
set SELECTED (sk --ansi -c 'rg --color=always --line-number \"{}\"')
echo (cat $SELECTED | sed 's/\(\:[0-9]*\).*/\1/' | tr ':' ' ')
end

@ -0,0 +1,12 @@
{ config, lib, pkgs, ... } @ args:
{
programs.fish = {
enable = true;
shellInit = import ./config.nix args;
};
home.packages = [
pkgs.any-nix-shell
];
}

@ -0,0 +1,12 @@
{ config, lib, pkgs, home-manager, ... } @ args:
let cfg = config.libkookie.base.fish;
in
with lib;
{
options.libkookie.base.fish = {
enable = mkEnableOption "Fish shell handling";
};
config = (import ./core args);
}

@ -0,0 +1,9 @@
{ config, lib, pkgs, ... } @ args:
{
options.libkookie.base.fish = {
enable = lib.mkEnableOption "fish userspace handling";
};
config = (import ./core/setup.nix args);
}

@ -7,5 +7,6 @@
# Add modules based on use-case
./workstation
./base
];
}

Loading…
Cancel
Save