config/users/pbsds/home/modules/jump.nix

72 lines
2.0 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.jump;
enabled = cfg.enableBash || cfg.enableZsh;
in {
meta.maintainers = [ hm.maintainers.pbsds ];
options.programs.jump = {
# Jumping around with symbolic links
# Based on http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
enableBash = mkEnableOption "jump - Quickly Navigate your Filesystem";
enableZsh = mkEnableOption "jump - Quickly Navigate your Filesystem";
marksPath = mkOption {
type = types.str;
default = "$HOME/.marks";
description = ''
Where the jump marks are stored
'';
};
};
config = mkIf enabled {
#home.packages = [ cfg.package ];
home.sessionVariables = { _JUMP_MARKPATH = cfg.marksPath; };
programs = let
rcScript = ''
function jump {
pushd . > /dev/null
cd -P "$_JUMP_MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p "$_JUMP_MARKPATH" &&
test ! -L "$_JUMP_MARKPATH/$1" \
&& ln -s "$(pwd)" "$_JUMP_MARKPATH/$1" \
|| echo "mark already exists!"
}
function unmark {
test ! -z "$1" \
&& rm -i "$_JUMP_MARKPATH/$1"
}
function marks {
#ls -l "$_JUMP_MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
ls --color=always -l "$_JUMP_MARKPATH" | tr -s ' ' | cut -d' ' -f9- | sed -e 's/ -> /§/g' | column -t -s '§' -o ' -> '
}
_complete_jump_marks() {
local curw=''${COMP_WORDS[COMP_CWORD]}
local wordlist=$(find $_JUMP_MARKPATH -type l -printf "%f\n")
COMPREPLY=($(compgen -W ''\'''${wordlist[@]}' -- "$curw"))
return 0
}
complete -F _complete_jump_marks jump unmark
'';
in {
# TODO: fish
bash.initExtra = mkIf cfg.enableBash rcScript;
zsh.initExtra = mkIf cfg.enableZsh rcScript;
};
};
}