sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

.nnn-plugin-helper (1256B)


      1 #!/usr/bin/env sh
      2 
      3 # Description: Helper script for plugins
      4 #
      5 # Shell: POSIX compliant
      6 # Author: Anna Arad
      7 
      8 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
      9 export selection
     10 
     11 ## Set CUR_CTX to 1 to open directory in current context
     12 CUR_CTX=0
     13 export CUR_CTX
     14 
     15 NNN_PREFER_SELECTION="${NNN_PREFER_SELECTION:-0}"
     16 export NNN_PREFER_SELECTION
     17 
     18 ## Ask nnn to switch to directory $1 in context $2.
     19 ## If $2 is not provided, the function asks explicitly.
     20 nnn_cd () {
     21     dir="$1"
     22 
     23     if [ -z "$NNN_PIPE" ]; then
     24         echo "No pipe file found" 1>&2
     25         return
     26     fi
     27 
     28     if [ -n "$2" ]; then
     29         context=$2
     30     elif [ $CUR_CTX -ne 1 ]; then
     31         printf "Choose context 1-4 (blank for current): "
     32         read -r context
     33     fi
     34 
     35     printf "%s" "${context:-0}c$dir" > "$NNN_PIPE"
     36 }
     37 
     38 cmd_exists () {
     39     type "$1" > /dev/null 2>&1
     40     echo $?
     41 }
     42 
     43 nnn_use_selection() {
     44     if ! [ -s "$selection" ]; then
     45         return 1
     46     fi
     47 
     48     if [ "$NNN_PREFER_SELECTION" -eq 1 ]; then
     49         return 0
     50     else
     51         [ -n "$1" ] && printf "%s " "$1"
     52         printf "(s)election/(c)urrent? [default=c] "
     53         read -r resp__
     54 
     55         if [ "$resp__" = "s" ]; then
     56             return 0
     57         else
     58             return 1
     59         fi
     60     fi
     61 }