Commit ae9bab469d1e

Vincent Demeester <vincent@sbr.pm>
2019-06-28 14:35:01
profiles.zsh: add zsh-z and j function
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 13c095f
Changed files (2)
modules
profiles
assets
zsh
modules/profiles/assets/zsh/j
@@ -0,0 +1,30 @@
+local root=~/src/github.com/
+local res results args
+
+while getopts "np" opt; do
+  if [[ $opt = "?" ]]; then
+    print -r -- "$myname: unrecognized option: -$OPTARG" >&2
+    return 1
+  fi
+  eval "opt_$opt=\${OPTARG:--\$opt}"
+done
+(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
+
+local fnd=$1
+type -f zshz 2>/dev/null >/dev/null || opt_n=true
+
+if [[ -n ${fnd} ]];then
+
+    [[ -z ${opt_n} ]] && {
+        local zz=$(zshz -e ${fnd})
+        [[ -n ${zz} ]] && { echo "ZSHZ: ${zz}"; [[ -z ${opt_p} ]] && cd ${zz}; return;}
+    }
+
+    local results=($(fd -d 2 -t d . ${root}|egrep -i "${fnd}"))
+    [[ ${#results} == 1 ]] && { echo ${results}; [[ -z ${opt_p} ]] && cd ${results} ; return;}
+    [[ ${#results} == 0 ]] && { echo "No results found for ${fnd}"; return 1;}
+    args="-q ${fnd}"
+fi
+
+res=$(fd -d 2 -t d . ${root}|sed "s,${root},,"|fzf --height 50% --border ${args})
+[[ -n ${res} ]] && {echo ${root}${res}; [[ -z ${opt_p} ]]  && cd ${root}${res} ; }
modules/profiles/zsh.nix
@@ -19,6 +19,7 @@ in
       home.packages = with pkgs; [
         zsh-syntax-highlighting
       ];
+      home.file.".config/zsh/functions/j".source = ./assets/zsh/j;
       programs.zsh = {
         enable = true;
         dotDir = ".config/zsh";
@@ -45,7 +46,16 @@ in
                rev = "26e2d67d566bfcc741891c8e063a00e0674abc92";
                sha256 = "0n88w4k5vaz1iyikpmlzdrrkxmfn91x5s4q405k1fxargr1w6bmx";
              };
-           }
+          }
+          {
+             name = "zsh-z";
+             src = pkgs.fetchFromGitHub {
+               owner = "agkozak";
+               repo = "zsh-z";
+               rev = "5b903f8f5489783ee2a4af668a941b7d9a02efc9";
+               sha256 = "07h6ksiqgqyf5m84hv5xf4jcqrl8q1cj8wd4z52cjmy82kk10fkn";
+             };
+          }
           {
              name = "async";
              src = pkgs.fetchFromGitHub {
@@ -54,7 +64,7 @@ in
                rev = "v1.7.0";
                sha256 = "1jbbypgn0r4pilhv2s2p11vbkkvlnf75wrhxfcvr7bfjpzyp9wbc";
              };
-           }
+          }
           {
              name = "pure";
              src = pkgs.fetchFromGitHub {
@@ -63,9 +73,12 @@ in
                rev = "v1.10.3";
                sha256 = "0zjgnlw01ri0brx108n6miw4y0cxd6al1bh28m8v8ygshm94p1zx";
              };
-           }
+          }
         ];
         initExtra = ''
+          path+="$HOME/${config.programs.zsh.dotDir}/functions"
+          fpath+="$HOME/${config.programs.zsh.dotDir}/functions"
+          for func ($HOME/${config.programs.zsh.dotDir}/functions) autoload -U $func/*(x:t)
           IS_SERIAL=0
           case $TTY in
             /dev/ttyS[0-9]*|/dev/ttyUSB[0-9]*)
@@ -86,7 +99,6 @@ in
           ZSH_HIGHLIGHT_PATTERNS+=('rm -fR *' 'fg=white,bold,bg=red')
           ZSH_HIGHLIGHT_PATTERNS+=('rm -fr *' 'fg=white,bold,bg=red')
           # prompt
-          autoload -Uz promptinit; promptinit
           PURE_CMD_MAX_EXEC_TIME=10
           zstyle :prompt:pure:path color white
           PURE_PROMPT_SYMBOL='λ'
@@ -98,7 +110,7 @@ in
             PURE_PROMPT_SYMBOL='>'
             prompt_pure_set_title() {}
           fi
-          prompt pure
+          zstyle ':completion:*' menu select
         '';
         profileExtra = ''
           if [ -e /home/vincent/.nix-profile/etc/profile.d/nix.sh ]; then . /home/vincent/.nix-profile/etc/profile.d/nix.sh; fi
@@ -109,10 +121,6 @@ in
         enable = true;
         enableZshIntegration = true;
       };
-      programs.z-lua = {
-        enable = true;
-        enableZshIntegration = true;
-      };
     }
     (mkIf config.profiles.emacs.enable {
       /*programs.zsh.initExtra = ''