[neon/neon-packaging/nvm/Neon/unstable] debian: refine and base everything around /etc/profile.d/nvm-profile.sh

Carlos De Maine null at kde.org
Tue Sep 5 15:25:55 BST 2023


Git commit 71a9983694621ababf36b52ee9ec5c5a463a0b01 by Carlos De Maine.
Committed on 05/09/2023 at 16:25.
Pushed by carlosdem into branch 'Neon/unstable'.

refine and base everything around /etc/profile.d/nvm-profile.sh

M  +1    -1    debian/control
A  +99   -0    debian/nvm.bash-completion
M  +1    -0    debian/nvm.install
A  +2    -0    debian/nvm.substvars
M  +11   -2    debian/patches/0001_add_convenience_scripts
M  +5    -7    debian/postinst
M  +4    -2    debian/rules

https://invent.kde.org/neon/neon-packaging/nvm/-/commit/71a9983694621ababf36b52ee9ec5c5a463a0b01

diff --git a/debian/control b/debian/control
index 62fd5dd..10bff1d 100644
--- a/debian/control
+++ b/debian/control
@@ -6,7 +6,7 @@ Standards-Version: 4.6.0
 Vcs-Git: https://github.com/nvm-sh/nvm.git
 Vcs-Browser: https://github.com/nvm-sh/nvm
 Maintainer: neon at kde.org
-Build-Depends: debhelper-compat (= 13), bash,
+Build-Depends: debhelper-compat (= 13), bash, bash-completion, dh-sequence-bash-completion
 Rules-Requires-Root: no
 
 Package: nvm
diff --git a/debian/nvm.bash-completion b/debian/nvm.bash-completion
new file mode 100644
index 0000000..e1f987c
--- /dev/null
+++ b/debian/nvm.bash-completion
@@ -0,0 +1,99 @@
+#!/usr/bin/env bash
+
+# bash completion for Node Version Manager (NVM)
+
+if ! command -v nvm &> /dev/null; then
+  return
+fi
+
+__nvm_generate_completion() {
+  declare current_word
+  current_word="${COMP_WORDS[COMP_CWORD]}"
+  # shellcheck disable=SC2207
+  COMPREPLY=($(compgen -W "$1" -- "${current_word}"))
+  return 0
+}
+
+__nvm_commands() {
+  declare current_word
+  declare command
+
+  current_word="${COMP_WORDS[COMP_CWORD]}"
+
+  COMMANDS='
+    help install uninstall use run exec
+    alias unalias reinstall-packages
+    current list ls list-remote ls-remote
+    install-latest-npm
+    cache deactivate unload
+    version version-remote which'
+
+  if [ ${#COMP_WORDS[@]} == 4 ]; then
+
+    command="${COMP_WORDS[COMP_CWORD - 2]}"
+    case "${command}" in
+      alias) __nvm_installed_nodes ;;
+    esac
+
+  else
+
+    case "${current_word}" in
+      -*) __nvm_options ;;
+      *) __nvm_generate_completion "${COMMANDS}" ;;
+    esac
+
+  fi
+}
+
+__nvm_options() {
+  OPTIONS=''
+  __nvm_generate_completion "${OPTIONS}"
+}
+
+__nvm_installed_nodes() {
+  __nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)"
+}
+
+__nvm_aliases() {
+  declare aliases
+  aliases=""
+  if [ -d "${NVM_DIR}/alias" ]; then
+    aliases="$(command cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")"
+  fi
+  echo "${aliases} node stable unstable iojs"
+}
+
+__nvm_alias() {
+  __nvm_generate_completion "$(__nvm_aliases)"
+}
+
+__nvm() {
+  declare previous_word
+  previous_word="${COMP_WORDS[COMP_CWORD - 1]}"
+
+  case "${previous_word}" in
+    use | run | exec | ls | list | uninstall) __nvm_installed_nodes ;;
+    alias | unalias) __nvm_alias ;;
+    *) __nvm_commands ;;
+  esac
+
+  return 0
+}
+
+# complete is a bash builtin, but recent versions of ZSH come with a function
+# called bashcompinit that will create a complete in ZSH. If the user is in
+# ZSH, load and run bashcompinit before calling the complete function.
+if [[ -n ${ZSH_VERSION-} ]]; then
+  # First calling compinit (only if not called yet!)
+  # and then bashcompinit as mentioned by zsh man page.
+  if ! command -v compinit > /dev/null; then
+    autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
+      compinit -u
+    else
+      compinit
+    fi
+  fi
+  autoload -U +X bashcompinit && bashcompinit
+fi
+
+complete -o default -F __nvm nvm
diff --git a/debian/nvm.install b/debian/nvm.install
index 275c78f..707899c 100644
--- a/debian/nvm.install
+++ b/debian/nvm.install
@@ -1 +1,2 @@
+etc/
 usr/share/nvm/
diff --git a/debian/nvm.substvars b/debian/nvm.substvars
new file mode 100644
index 0000000..978fc8b
--- /dev/null
+++ b/debian/nvm.substvars
@@ -0,0 +1,2 @@
+misc:Depends=
+misc:Pre-Depends=
diff --git a/debian/patches/0001_add_convenience_scripts b/debian/patches/0001_add_convenience_scripts
index f96c0be..8081619 100644
--- a/debian/patches/0001_add_convenience_scripts
+++ b/debian/patches/0001_add_convenience_scripts
@@ -1,12 +1,21 @@
 --- /dev/null
++++ b/nvm-profile.sh
+@@ -0,0 +1,6 @@
++# Maintainer: Tom Wadley <tom at tomwadley.net>
++
++source /usr/share/nvm/init-nvm.sh
++source /usr/share/nvm/install-nvm-exec
++PATH="$HOME/.local/bin:$PATH"
++#export npm_config_prefix="$HOME/.local"
+--- /dev/null
 +++ b/init-nvm.sh
 @@ -0,0 +1,6 @@
 +# Maintainer: Tom Wadley <tom at tomwadley.net>
 +
 +[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
-+ln -s /usr/share/nvm/bash_completion /usr/share/bash-completion/completions/nvm
 +source /usr/share/nvm/nvm.sh
-+source /usr/share/nvm/bash_completion
++source /usr/share/bash-completion/completions/nvm
++source /usr/share/nvm/install-nvm-exec
 --- /dev/null
 +++ b/install-nvm-exec
 @@ -0,0 +1,4 @@
diff --git a/debian/postinst b/debian/postinst
index 5499681..2a29a72 100644
--- a/debian/postinst
+++ b/debian/postinst
@@ -1,13 +1,11 @@
 #!/bin/bash
 # This `DEBIAN/postinst` script is run post-installation
 # setup nvm in home dir
-source /usr/share/nvm/init-nvm.sh
-source /usr/share/nvm/install-nvm-exec
-source ~/.nvm/nvm.sh
-# initialise system wide installs
-echo 'PATH="$HOME/.local/bin:$PATH"
-export npm_config_prefix="$HOME/.local"' >> ~/.profile
-echo 'source ~/.nvm/nvm.sh' >> ~/.bashrc
+#source /usr/share/nvm/init-nvm.sh
+#source /usr/share/nvm/install-nvm-exec
+#source /etc/bash.bashrc
+source /etc/profile.d/nvm-profile.sh
+
 # install nodejs 18.5.0 and make system wide default
 nvm install 18.5.0
 nvm alias default 18.5.0
diff --git a/debian/rules b/debian/rules
index f0e54d8..9542245 100755
--- a/debian/rules
+++ b/debian/rules
@@ -17,7 +17,9 @@ override_dh_prep:
 	install -Dm644 nvm.sh "usr/share/nvm/nvm.sh"
 	# nvm-exec script for 'nvm exec' command
 	install -Dm755 nvm-exec "usr/share/nvm/nvm-exec"
-	# bash completion
-	install -Dm644 bash_completion "usr/share/nvm/bash_completion"
+	# nvm-profile.sh to init nvm for each shell session
+	install -Dm644 nvm-profile.sh "etc/profile.d/nvm-profile.sh"
+	# bash completion should be auto by dh
+#	install -Dm644 bash_completion "usr/share/nvm/bash_completion"
 	# license
 	install -Dm644 LICENSE.md "usr/share/licenses/nvm/LICENSE.md"


More information about the Neon-commits mailing list