From f700d4b0404169f7e4beab940890a53de4cb79ba Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Sat, 5 Oct 2019 22:10:04 +0000 Subject: Adding nix and base modules --- modules/base/fish/functions/__fancy_history.fish | 5 +++ .../fish/functions/__history_previous_command.fish | 8 +++++ .../__history_previous_command_arguments.fish | 9 +++++ modules/base/fish/functions/__kakoune.fish | 28 +++++++++++++++ modules/base/fish/functions/__skim_cd.fish | 6 ++++ modules/base/fish/functions/e.fish | 12 +++++++ modules/base/fish/functions/fish_prompt.fish | 34 ++++++++++++++++++ modules/base/fish/functions/fish_right_prompt.fish | 1 + .../fish/functions/fish_user_key_bindings.fish | 6 ++++ modules/base/fish/functions/gen-shell.fish | 22 ++++++++++++ modules/base/fish/functions/k.fish | 18 ++++++++++ modules/base/fish/functions/nrepl.fish | 7 ++++ modules/base/fish/functions/nxs.fish | 12 +++++++ modules/base/fish/functions/restart.fish | 3 ++ modules/base/fish/functions/rvm.fish | 40 ++++++++++++++++++++++ modules/base/fish/functions/search.fish | 4 +++ 16 files changed, 215 insertions(+) create mode 100644 modules/base/fish/functions/__fancy_history.fish create mode 100644 modules/base/fish/functions/__history_previous_command.fish create mode 100644 modules/base/fish/functions/__history_previous_command_arguments.fish create mode 100644 modules/base/fish/functions/__kakoune.fish create mode 100644 modules/base/fish/functions/__skim_cd.fish create mode 100644 modules/base/fish/functions/e.fish create mode 100644 modules/base/fish/functions/fish_prompt.fish create mode 100644 modules/base/fish/functions/fish_right_prompt.fish create mode 100644 modules/base/fish/functions/fish_user_key_bindings.fish create mode 100644 modules/base/fish/functions/gen-shell.fish create mode 100644 modules/base/fish/functions/k.fish create mode 100644 modules/base/fish/functions/nrepl.fish create mode 100644 modules/base/fish/functions/nxs.fish create mode 100644 modules/base/fish/functions/restart.fish create mode 100644 modules/base/fish/functions/rvm.fish create mode 100644 modules/base/fish/functions/search.fish (limited to 'modules/base/fish/functions') diff --git a/modules/base/fish/functions/__fancy_history.fish b/modules/base/fish/functions/__fancy_history.fish new file mode 100644 index 00000000000..7ea5a12d417 --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/__history_previous_command.fish b/modules/base/fish/functions/__history_previous_command.fish new file mode 100644 index 00000000000..40555452230 --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/__history_previous_command_arguments.fish b/modules/base/fish/functions/__history_previous_command_arguments.fish new file mode 100644 index 00000000000..adc8fbd273d --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/__kakoune.fish b/modules/base/fish/functions/__kakoune.fish new file mode 100644 index 00000000000..2515edaa00a --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/__skim_cd.fish b/modules/base/fish/functions/__skim_cd.fish new file mode 100644 index 00000000000..b4ae4234bed --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/e.fish b/modules/base/fish/functions/e.fish new file mode 100644 index 00000000000..cb3f2d6aaf4 --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/fish_prompt.fish b/modules/base/fish/functions/fish_prompt.fish new file mode 100644 index 00000000000..b6280bfbda6 --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/fish_right_prompt.fish b/modules/base/fish/functions/fish_right_prompt.fish new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/modules/base/fish/functions/fish_right_prompt.fish @@ -0,0 +1 @@ + diff --git a/modules/base/fish/functions/fish_user_key_bindings.fish b/modules/base/fish/functions/fish_user_key_bindings.fish new file mode 100644 index 00000000000..9799d461120 --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/gen-shell.fish b/modules/base/fish/functions/gen-shell.fish new file mode 100644 index 00000000000..0c48fe2a5c3 --- /dev/null +++ b/modules/base/fish/functions/gen-shell.fish @@ -0,0 +1,22 @@ +function gen-shell + if not test $argv[1] + echo "Usage: gen-shell " + return 1 + end + + if test -e default.nix + echo "Refusing to override existing `default.nix`!" + return 1 + end + + set name $argv[1] + echo "with import {}; + +stdenv.mkDerivation { + name = \"$name\"; + buildInputs = with pkgs; [ + # Hier könnte Ihre Werbung stehen + ]; +}" > default.nix + bat default.nix +end diff --git a/modules/base/fish/functions/k.fish b/modules/base/fish/functions/k.fish new file mode 100644 index 00000000000..55b43ad5107 --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/nrepl.fish b/modules/base/fish/functions/nrepl.fish new file mode 100644 index 00000000000..75febe575e4 --- /dev/null +++ b/modules/base/fish/functions/nrepl.fish @@ -0,0 +1,7 @@ +function nrepl + if test $argv[1] + nix repl $argv + else + nix repl '' + end +end diff --git a/modules/base/fish/functions/nxs.fish b/modules/base/fish/functions/nxs.fish new file mode 100644 index 00000000000..a3fd915bbcc --- /dev/null +++ b/modules/base/fish/functions/nxs.fish @@ -0,0 +1,12 @@ +function nxs + if test $argv[1] + nix run -f '' $argv + else + if test -e default.nix + nix-shell + else + echo "No `default.nix`" + return 1 + end + end +end diff --git a/modules/base/fish/functions/restart.fish b/modules/base/fish/functions/restart.fish new file mode 100644 index 00000000000..191fe791e81 --- /dev/null +++ b/modules/base/fish/functions/restart.fish @@ -0,0 +1,3 @@ +function restart + clear; exec fish +end diff --git a/modules/base/fish/functions/rvm.fish b/modules/base/fish/functions/rvm.fish new file mode 100644 index 00000000000..834e73e5f75 --- /dev/null +++ b/modules/base/fish/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/modules/base/fish/functions/search.fish b/modules/base/fish/functions/search.fish new file mode 100644 index 00000000000..11c89dc575d --- /dev/null +++ b/modules/base/fish/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 -- cgit v1.2.3