diff options
author | Mx Kookie <kookie@spacekookie.de> | 2020-12-23 02:19:40 +0100 |
---|---|---|
committer | Mx Kookie <kookie@spacekookie.de> | 2020-12-23 02:21:20 +0100 |
commit | d0b1a2d3e90f72380d101f10d4caae2a750986b5 (patch) | |
tree | ea72175345ff6551671ee5315f43c4ef961dfa90 /infra | |
parent | e39465caf3293f56d0a9bccee599ea3f902fc2b2 (diff) |
libkookie: base: init module with shell tools, git, and fish support
Diffstat (limited to 'infra')
30 files changed, 387 insertions, 0 deletions
diff --git a/infra/libkookie/configuration/base/default.nix b/infra/libkookie/configuration/base/default.nix new file mode 100644 index 000000000000..a71f54a00d2e --- /dev/null +++ b/infra/libkookie/configuration/base/default.nix @@ -0,0 +1,8 @@ +/** + * A set of userspace tools to install for all systems + */ +{ config, lib, pkgs, ... }: + +{ + imports = [ ./fish ./git ./shell ] +} diff --git a/infra/libkookie/configuration/base/fish/default.nix b/infra/libkookie/configuration/base/fish/default.nix new file mode 100644 index 000000000000..a817f1f51669 --- /dev/null +++ b/infra/libkookie/configuration/base/fish/default.nix @@ -0,0 +1,6 @@ +{ config, pkgs, ... }: + +{ + imports = [ <modules/base/fish/hm.nix> ]; + libkookie.base.fish.enable = true; +} diff --git a/infra/libkookie/configuration/base/git/default.nix b/infra/libkookie/configuration/base/git/default.nix new file mode 100644 index 000000000000..36df829ba52b --- /dev/null +++ b/infra/libkookie/configuration/base/git/default.nix @@ -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 ]); +} diff --git a/infra/libkookie/configuration/base/shell/default.nix b/infra/libkookie/configuration/base/shell/default.nix new file mode 100644 index 000000000000..32a37330c3f0 --- /dev/null +++ b/infra/libkookie/configuration/base/shell/default.nix @@ -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 + ]; + }; +} diff --git a/infra/libkookie/modules/base/default.nix b/infra/libkookie/modules/base/default.nix new file mode 100644 index 000000000000..aed5728760e7 --- /dev/null +++ b/infra/libkookie/modules/base/default.nix @@ -0,0 +1,7 @@ +{ ... }: + +{ + imports = [ + ./fish + ]; +} diff --git a/infra/libkookie/modules/base/fish/core/alias.fish b/infra/libkookie/modules/base/fish/core/alias.fish new file mode 100644 index 000000000000..078b21dca8c2 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/alias.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 ~)" diff --git a/infra/libkookie/modules/base/fish/core/binds.fish b/infra/libkookie/modules/base/fish/core/binds.fish new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/binds.fish @@ -0,0 +1 @@ + diff --git a/infra/libkookie/modules/base/fish/core/config.fish b/infra/libkookie/modules/base/fish/core/config.fish new file mode 100644 index 000000000000..9bc6c53c5832 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/config.fish @@ -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)'...' diff --git a/infra/libkookie/modules/base/fish/core/config.nix b/infra/libkookie/modules/base/fish/core/config.nix new file mode 100644 index 000000000000..4cdf7b487609 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/config.nix @@ -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} +'' diff --git a/infra/libkookie/modules/base/fish/core/default.nix b/infra/libkookie/modules/base/fish/core/default.nix new file mode 100644 index 000000000000..9958621c9c43 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/default.nix @@ -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; +} diff --git a/infra/libkookie/modules/base/fish/core/functions/__fancy_history.fish b/infra/libkookie/modules/base/fish/core/functions/__fancy_history.fish new file mode 100644 index 000000000000..7ea5a12d4174 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/__fancy_history.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/__history_previous_command.fish b/infra/libkookie/modules/base/fish/core/functions/__history_previous_command.fish new file mode 100644 index 000000000000..40555452230a --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/__history_previous_command.fish @@ -0,0 +1,8 @@ +function __history_previous_command + switch (commandline -t) + case "!" + commandline -t $history[1]; commandline -f repaint + case "*" + commandline -i ! + end +end diff --git a/infra/libkookie/modules/base/fish/core/functions/__history_previous_command_arguments.fish b/infra/libkookie/modules/base/fish/core/functions/__history_previous_command_arguments.fish new file mode 100644 index 000000000000..adc8fbd273d3 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/__history_previous_command_arguments.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/__kakoune.fish b/infra/libkookie/modules/base/fish/core/functions/__kakoune.fish new file mode 100644 index 000000000000..2515edaa00a0 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/__kakoune.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/__skim_cd.fish b/infra/libkookie/modules/base/fish/core/functions/__skim_cd.fish new file mode 100644 index 000000000000..b4ae4234bed9 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/__skim_cd.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/e.fish b/infra/libkookie/modules/base/fish/core/functions/e.fish new file mode 100644 index 000000000000..cb3f2d6aaf47 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/e.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/fish_prompt.fish b/infra/libkookie/modules/base/fish/core/functions/fish_prompt.fish new file mode 100644 index 000000000000..b6280bfbda6b --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/fish_prompt.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/fish_right_prompt.fish b/infra/libkookie/modules/base/fish/core/functions/fish_right_prompt.fish new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/fish_right_prompt.fish @@ -0,0 +1 @@ + diff --git a/infra/libkookie/modules/base/fish/core/functions/fish_user_key_bindings.fish b/infra/libkookie/modules/base/fish/core/functions/fish_user_key_bindings.fish new file mode 100644 index 000000000000..9799d4611209 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/fish_user_key_bindings.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/gen-shell.fish b/infra/libkookie/modules/base/fish/core/functions/gen-shell.fish new file mode 100644 index 000000000000..03ec597cd686 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/gen-shell.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/k.fish b/infra/libkookie/modules/base/fish/core/functions/k.fish new file mode 100644 index 000000000000..55b43ad51070 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/k.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/nrepl.fish b/infra/libkookie/modules/base/fish/core/functions/nrepl.fish new file mode 100644 index 000000000000..75febe575e49 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/nrepl.fish @@ -0,0 +1,7 @@ +function nrepl + if test $argv[1] + nix repl $argv + else + nix repl '<nixpkgs>' + end +end diff --git a/infra/libkookie/modules/base/fish/core/functions/nxs.fish b/infra/libkookie/modules/base/fish/core/functions/nxs.fish new file mode 100644 index 000000000000..a3fd915bbcce --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/nxs.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/restart.fish b/infra/libkookie/modules/base/fish/core/functions/restart.fish new file mode 100644 index 000000000000..191fe791e816 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/restart.fish @@ -0,0 +1,3 @@ +function restart + clear; exec fish +end diff --git a/infra/libkookie/modules/base/fish/core/functions/rvm.fish b/infra/libkookie/modules/base/fish/core/functions/rvm.fish new file mode 100644 index 000000000000..834e73e5f756 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/rvm.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/functions/search.fish b/infra/libkookie/modules/base/fish/core/functions/search.fish new file mode 100644 index 000000000000..11c89dc575d3 --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/functions/search.fish @@ -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 diff --git a/infra/libkookie/modules/base/fish/core/setup.nix b/infra/libkookie/modules/base/fish/core/setup.nix new file mode 100644 index 000000000000..742da6c9fa7c --- /dev/null +++ b/infra/libkookie/modules/base/fish/core/setup.nix @@ -0,0 +1,12 @@ +{ config, lib, pkgs, ... } @ args: + +{ + programs.fish = { + enable = true; + shellInit = import ./config.nix args; + }; + + home.packages = [ + pkgs.any-nix-shell + ]; +} diff --git a/infra/libkookie/modules/base/fish/default.nix b/infra/libkookie/modules/base/fish/default.nix new file mode 100644 index 000000000000..15f91dd1955d --- /dev/null +++ b/infra/libkookie/modules/base/fish/default.nix @@ -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); +} diff --git a/infra/libkookie/modules/base/fish/hm.nix b/infra/libkookie/modules/base/fish/hm.nix new file mode 100644 index 000000000000..9b3923510b05 --- /dev/null +++ b/infra/libkookie/modules/base/fish/hm.nix @@ -0,0 +1,9 @@ +{ config, lib, pkgs, ... } @ args: + +{ + options.libkookie.base.fish = { + enable = lib.mkEnableOption "fish userspace handling"; + }; + + config = (import ./core/setup.nix args); +} diff --git a/infra/libkookie/modules/default.nix b/infra/libkookie/modules/default.nix index 5d4e378d01cd..227d6e83aa69 100644 --- a/infra/libkookie/modules/default.nix +++ b/infra/libkookie/modules/default.nix @@ -7,5 +7,6 @@ # Add modules based on use-case ./workstation + ./base ]; } |