Browse Source

npmsearch: save packages as dev deps

DanielFGray 2 years ago
parent
commit
4ac05475cd
1 changed files with 9 additions and 2 deletions
  1. 9
    2
      npmsearch

+ 9
- 2
npmsearch View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 declare -a args
4 4
 declare -a packages
5
+declare savedev=0
5 6
 
6 7
 declare -A colors
7 8
 colors[red]=$(tput setaf 1)
@@ -61,13 +62,13 @@ fi
61 62
 mapfile -t packages < <(fzf --multi --ansi --reverse \
62 63
   --bind='Ctrl-X:toggle-preview' \
63 64
   --expect='Ctrl-d,enter' \
64
-  --preview-window='hidden' \
65
+  --preview-window='hidden:down' \
65 66
   --preview="$preview" \
66 67
   <<< "$search" || exit 1)
67 68
 
68 69
 key="${packages[0]}"
69 70
 case "${key,,}" in
70
-  ctrl-d) args+=( -D ) ;;
71
+  ctrl-d) savedev=1 ;;
71 72
 esac
72 73
 
73 74
 packages=( $(printf '%s\n' "${packages[@]:1}" | cut -d' ' -f1) )
@@ -75,8 +76,14 @@ packages=( $(printf '%s\n' "${packages[@]:1}" | cut -d' ' -f1) )
75 76
 printf "installing...\r"
76 77
 if (( ${#packages[@]} > 0 )); then
77 78
   if has yarn; then
79
+    (( savedev > 0 )) && args+=( -D )
78 80
     yarn add "${args[@]}" "${packages[@]}"
79 81
   else
82
+    if (( savedev > 0 )); then
83
+      args+=( -D )
84
+    else
85
+      args+=( -S )
86
+    fi
80 87
     npm i "${args[@]}" "${packages[@]}"
81 88
   fi
82 89
 else

Loading…
Cancel
Save