marcosnils / bin

Effortless binary manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relative paths to $HOME

rothgar opened this issue · comments

I synced my home directory from another computer that has a different username and /home path. This causes bin to think my executables should be in a different directory between each computer.

Is it possible to download and track downloads in a relative path to my $HOME folder instead of full path?

If it's not possible can you let me know where bin stores the information about the downloads so I can ignore it between my computer syncs? I see it's trying to open .bin/config.json but I don't actually have that file on my computer so I'm not sure where the config is being stored.

Reading through #89 I was able to find the config file is actually ~/.config/bin/config.json and can see the full paths in that file.

I tried changing the $HOME path to ~/ but and update still didn't work

bin update
   • ~/.local/bin/bin v0.11.0 -> v0.12.0 (https://github.com/marcosnils/bin/releases/tag/v0.12.0)

Do you want to continue? [Y/n] y
   • Getting v0.12.0 release for marcosnils/bin
   • Starting download of https://github.com/marcosnils/bin/releases/download/v0.12.0/bin_0.12.0_Linux_x86_64
14.36 MiB / 14.36 MiB [-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 243.28 MiB p/s 0s
   ⨯ command failed            error=Error installing binary open ~/.local/bin/bin: no such file or directory

I synced my home directory from another computer that has a different username and /home path. This causes bin to think my executables should be in a different directory between each computer.

that's a good observation... I'm not sure if we can do something like ~/ since that's shell expantion but setting something $HOME/bin is definitely possible. Would that be enough for your case Justin?

Just pushed a branch here with the env variable feature. I've did some preliminary tests but I'd love if you can help me validate that your use-case is still solved 🙏

https://github.com/marcosnils/bin/pull/new/feat/env_path

Cloned that branch and built bin and removed/installed a binary. I don't see anything different at the CLI and the path in ~/.config/bin/config.json still shows the full home path.

I also tried to update the default_path setting in the config to $HOME/.local/bin and reinstalled an app but it still shows the full path in the config. Is there something else I'm missing that I need to do?

I also tried to update the default_path setting in the config to $HOME/.local/bin and reinstalled an app but it still shows the full path in the config

Good catch, I missed making this change. I only implemented resolving the variables from the default_path, but it doesn't cascade to binaries path. I'll update this today.

Good catch, I missed making this change. I only implemented resolving the variables from the default_path, but it doesn't cascade to binaries path. I'll update this today.

@rothgar finally found the time to update the PR. Would love some feedback if you find the time 🙏

I built from PR 3 in a fresh machine and see an error on first run.

./bin help
   ⨯ Error loading config file open /home/jgarr/.bin/config.json: no such file or directory

I created the ~/.bin directory and touched ~/.bin/config.json. I ran bin again and was prompted for the default folder but nothing was written to the file. I kept getting prompted for the default folder each time until I installed a binary.

Once I installed a binary the config.json file was written to but still had hard coded home paths.

cat ~/.bin/config.json | jq
{
  "default_path": "/home/jgarr/.local/bin",
  "bins": {
    "/home/jgarr/.local/bin/kind-linux-amd64": {
      "path": "/home/jgarr/.local/bin/kind-linux-amd64",
      "remote_name": "kind-linux-amd64",
      "version": "v0.11.1",
      "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
      "url": "github.com/kubernetes-sigs/kind"
    }
  }
}

I created the ~/.bin directory and touched ~/.bin/config.json. I ran bin again and was prompted for the default folder but nothing was written to the file. I kept getting prompted for the default folder each time until I installed a binary.

weird... I'll check this. Thx for reporting

Once I installed a binary the config.json file was written to but still had hard coded home paths.

Yes, if you replace your default_path with "$HOME/.local/bin" and install binaries after that, it should preserve the path correctly.

./bin help
⨯ Error loading config file open /home/jgarr/.bin/config.json: no such file or directory

This is strange, shouldn't have done that. Checking

Just ran bin in a fresh box and got this:

marcos:Projects/bin (feat/package_path) (⎈ |N/A)$ ./bin --debug
   • debug logs enabled
   • Config directory is: /home/marcos/.config/bin
   • User PATH is [/home/marcos/bin:/home/marcos/miniconda3/bin:/home/marcos/.rbenv/plugins/ruby-build/bin:/home/marcos/.rbenv/shims:/home/marcos/.rbenv/bin:/home/marcos/.cargo/bin:/home/marcos/miniconda3/bin:/home/marcos/.rbenv/plugins/ruby-build/bin:/home/marcos/.rbenv/shims:/home/marcos/.rbenv/bin:/home/marcos/.krew/bin:/home/marcos/bin:/home/marcos/.nvm/versions/node/v16.13.2/bin:/home/marcos/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/home/marcos/.yarn/bin:/home/marcos/Projects/gopath/bin:/usr/share/bcc/tools/:/home/marcos/.luarocks/bin:/home/marcos/.fzf/bin]
   • Checking path /home/marcos/bin
   • /home/marcos/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/miniconda3/bin
   • Error [Error setting download path [stat /home/marcos/miniconda3/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.rbenv/plugins/ruby-build/bin
   • Error [Error setting download path [stat /home/marcos/.rbenv/plugins/ruby-build/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.rbenv/shims
   • /home/marcos/.rbenv/shims seems to be a dir and writable, adding option.
   • Checking path /home/marcos/.rbenv/bin
   • Error [Error setting download path [stat /home/marcos/.rbenv/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.cargo/bin
   • /home/marcos/.cargo/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/miniconda3/bin
   • Error [Error setting download path [stat /home/marcos/miniconda3/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.rbenv/plugins/ruby-build/bin
   • Error [Error setting download path [stat /home/marcos/.rbenv/plugins/ruby-build/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.rbenv/shims
   • /home/marcos/.rbenv/shims seems to be a dir and writable, adding option.
   • Checking path /home/marcos/.rbenv/bin
   • Error [Error setting download path [stat /home/marcos/.rbenv/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.krew/bin
   • /home/marcos/.krew/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/bin
   • /home/marcos/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/.nvm/versions/node/v16.13.2/bin
   • /home/marcos/.nvm/versions/node/v16.13.2/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/bin
   • /home/marcos/bin seems to be a dir and writable, adding option.
   • Checking path /usr/local/sbin
   • Error [permission denied] checking path
   • Checking path /usr/local/bin
   • Error [permission denied] checking path
   • Checking path /usr/sbin
   • Error [permission denied] checking path
   • Checking path /usr/bin
   • Error [permission denied] checking path
   • Checking path /sbin
   • Error [permission denied] checking path
   • Checking path /bin
   • Error [permission denied] checking path
   • Checking path /usr/games
   • Error [permission denied] checking path
   • Checking path /usr/local/games
   • Error [permission denied] checking path
   • Checking path /snap/bin
   • Error [permission denied] checking path
   • Checking path /usr/local/go/bin
   • Error [permission denied] checking path
   • Checking path /home/marcos/.yarn/bin
   • Error [Error setting download path [stat /home/marcos/.yarn/bin: no such file or directory]] checking path
   • Checking path /home/marcos/Projects/gopath/bin
   • /home/marcos/Projects/gopath/bin seems to be a dir and writable, adding option.
   • Checking path /usr/share/bcc/tools/
   • Error [Error setting download path [stat /usr/share/bcc/tools/: no such file or directory]] checking path
   • Checking path /home/marcos/.luarocks/bin
   • Error [Error setting download path [stat /home/marcos/.luarocks/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.fzf/bin
   • /home/marcos/.fzf/bin seems to be a dir and writable, adding option.

Pick a default download dir:

 [1] /home/marcos/bin
 [2] /home/marcos/.rbenv/shims
 [3] /home/marcos/.cargo/bin
 [4] /home/marcos/.rbenv/shims
 [5] /home/marcos/.krew/bin
 [6] /home/marcos/bin
 [7] /home/marcos/.nvm/versions/node/v16.13.2/bin
 [8] /home/marcos/bin
 [9] /home/marcos/Projects/gopath/bin
 [10] /home/marcos/.fzf/bin
 Select an option:

Seems to be working as intended. I could add en option though to allow the user to specify their on path so they can use something like $HOME/bin or some other dir.

If you have the time, can you try bin --debug in a fresh install?

ok, I deleted ~/.bin and re-ran the commands

./bin --debug
   • debug logs enabled
   ⨯ Error loading config file open /home/jgarr/.bin/config.json: no such file or directory

❯ mkdir -p ~/.bin

❯ ./bin --debug
   • debug logs enabled
   • User PATH is [/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/jgarr/bin:/home/jgarr/.local/bin:/home/jgarr/.krew/bin:/home/jgarr/.toolbox/bin:/home/jgarr/go/bin://home/jgarr/.cargo/bin:/home/jgarr/.krew/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/jgarr/.rvm/bin]
   • Checking path /home/linuxbrew/.linuxbrew/bin
   • /home/linuxbrew/.linuxbrew/bin seems to be a dir and writable, adding option.
   • Checking path /home/linuxbrew/.linuxbrew/sbin
   • /home/linuxbrew/.linuxbrew/sbin seems to be a dir and writable, adding option.
   • Checking path /home/jgarr/bin
   • Error [no such file or directory] checking path
   • Checking path /home/jgarr/.local/bin
   • /home/jgarr/.local/bin seems to be a dir and writable, adding option.
   • Checking path /home/jgarr/.krew/bin
   • Error [no such file or directory] checking path
   • Checking path /home/jgarr/.toolbox/bin
   • Error [no such file or directory] checking path
   • Checking path /home/jgarr/go/bin
   • Error [no such file or directory] checking path
   • Checking path //home/jgarr/.cargo/bin
   • Error [no such file or directory] checking path
   • Checking path /home/jgarr/.krew/bin
   • Error [no such file or directory] checking path
   • Checking path /usr/local/bin
   • Error [permission denied] checking path
   • Checking path /usr/local/sbin
   • Error [permission denied] checking path
   • Checking path /usr/bin
   • Error [permission denied] checking path
   • Checking path /usr/sbin
   • Error [permission denied] checking path
   • Checking path /bin
   • Error [permission denied] checking path
   • Checking path /sbin
   • Error [permission denied] checking path
   • Checking path /home/jgarr/.rvm/bin
   • Error [no such file or directory] checking path

Pick a default download dir:

 [1] /home/linuxbrew/.linuxbrew/bin
 [2] /home/linuxbrew/.linuxbrew/sbin
 [3] /home/jgarr/.local/bin
 Select an option: 3
   • Download path set to /home/jgarr/.local/bin

 Path   Version         URL     Status

❯ echo '{"default_path": "$HOME/.local/bin"}' > ~/.bin/config.json

❯ ./bin install --debug github.com/kubernetes-sigs/kind
   • debug logs enabled
   • Download path set to $HOME/.local/bin
   • Getting latest release for kubernetes-sigs/kind
   • Checking binary form https://github.com/kubernetes-sigs/kind/releases/download/v0.11.1/kind-linux-amd64
   ⨯ command failed            error=Error installing binary open $HOME/.local/bin: no such file or directory

I verified that ~/.local/bin directory exists

hey @rothgar ! just pushed another update with a feature to allows the user to set a custom PATH when initializing bin the first time. However, I couldn't reproduce your error which seems to be correlated to a fix that I've recently pushed here: 496a2ba

marcos:Projects/bin (feat/env_path) (⎈ |N/A)$ go build && ./bin --debug install github.com/kubernetes-sigs/kind
   • debug logs enabled
   • Config directory is: /home/marcos/.config/bin
   • User PATH is [/home/marcos/bin:/home/marcos/miniconda3/bin:/home/marcos/.rbenv/plugins/ruby-build/bin:/home/marcos/.rbenv/shims:/home/marcos/.rbenv/bin:/home/marcos/.cargo/bin:/home/marcos/miniconda3/bin:/home/marcos/.rbenv/plugins/ruby-build/bin:/home/marcos/.rbenv/shims:/home/marcos/.rbenv/bin:/home/marcos/.krew/bin:/home/marcos/bin:/home/marcos/.nvm/versions/node/v16.13.2/bin:/home/marcos/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/home/marcos/.yarn/bin:/home/marcos/Projects/gopath/bin:/usr/share/bcc/tools/:/home/marcos/.luarocks/bin:/home/marcos/.fzf/bin]
   • Checking path /home/marcos/bin
   • /home/marcos/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/miniconda3/bin
   • Error [Error setting download path [stat /home/marcos/miniconda3/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.rbenv/plugins/ruby-build/bin
   • Error [Error setting download path [stat /home/marcos/.rbenv/plugins/ruby-build/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.rbenv/shims
   • /home/marcos/.rbenv/shims seems to be a dir and writable, adding option.
   • Checking path /home/marcos/.rbenv/bin
   • Error [Error setting download path [stat /home/marcos/.rbenv/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.cargo/bin
   • /home/marcos/.cargo/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/miniconda3/bin
   • Error [Error setting download path [stat /home/marcos/miniconda3/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.rbenv/plugins/ruby-build/bin
   • Error [Error setting download path [stat /home/marcos/.rbenv/plugins/ruby-build/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.rbenv/shims
   • /home/marcos/.rbenv/shims seems to be a dir and writable, adding option.
   • Checking path /home/marcos/.rbenv/bin
   • Error [Error setting download path [stat /home/marcos/.rbenv/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.krew/bin
   • /home/marcos/.krew/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/bin
   • /home/marcos/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/.nvm/versions/node/v16.13.2/bin
   • /home/marcos/.nvm/versions/node/v16.13.2/bin seems to be a dir and writable, adding option.
   • Checking path /home/marcos/bin
   • /home/marcos/bin seems to be a dir and writable, adding option.
   • Checking path /usr/local/sbin
   • Error [permission denied] checking path
   • Checking path /usr/local/bin
   • Error [permission denied] checking path
   • Checking path /usr/sbin
   • Error [permission denied] checking path
   • Checking path /usr/bin
   • Error [permission denied] checking path
   • Checking path /sbin
   • Error [permission denied] checking path
   • Checking path /bin
   • Error [permission denied] checking path
   • Checking path /usr/games
   • Error [permission denied] checking path
   • Checking path /usr/local/games
   • Error [permission denied] checking path
   • Checking path /snap/bin
   • Error [permission denied] checking path
   • Checking path /usr/local/go/bin
   • Error [permission denied] checking path
   • Checking path /home/marcos/.yarn/bin
   • Error [Error setting download path [stat /home/marcos/.yarn/bin: no such file or directory]] checking path
   • Checking path /home/marcos/Projects/gopath/bin
   • /home/marcos/Projects/gopath/bin seems to be a dir and writable, adding option.
   • Checking path /usr/share/bcc/tools/
   • Error [Error setting download path [stat /usr/share/bcc/tools/: no such file or directory]] checking path
   • Checking path /home/marcos/.luarocks/bin
   • Error [Error setting download path [stat /home/marcos/.luarocks/bin: no such file or directory]] checking path
   • Checking path /home/marcos/.fzf/bin
   • /home/marcos/.fzf/bin seems to be a dir and writable, adding option.

Pick a default download dir:

 [1] /home/marcos/bin
 [2] /home/marcos/.rbenv/shims
 [3] /home/marcos/.cargo/bin
 [4] /home/marcos/.krew/bin
 [5] /home/marcos/.nvm/versions/node/v16.13.2/bin
 [6] /home/marcos/Projects/gopath/bin
 [7] /home/marcos/.fzf/bin
 Select an option or type a custom value: $HOME/bin
   • Download path set to $HOME/bin
   • Getting latest release for kubernetes-sigs/kind
   • Removing kind-windows-amd64 (URL https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/37673593) with score 11 lower than 21
   • Removing kind-linux-ppc64le (URL https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/37673582) with score 16 lower than 21
   • Removing kind-linux-arm64 (URL https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/37673571) with score 16 lower than 21
   • Keeping kind-linux-amd64 (URL https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/37673562) with highest score 21
   • Removing kind-darwin-arm64 (URL https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/37673552) with score 6 lower than 21
   • Removing kind-darwin-amd64 (URL https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/37673531) with score 11 lower than 21
   • Checking binary from https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/37673562
   • Starting download of https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/37673562
6.50 MiB / 6.50 MiB [-------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 9.80 MiB p/s 1s
   • Copying for kind@v0.11.1 into /home/marcos/bin/kind
   • Done installing kind v0.11.1

Mind doing one last update and trying again? Make sure your env_path branch is fully updated and doesn't have any missing commits 🙏

Oh, I was building off pr/3 and not the env_path branch. I just rebuilt from the correct branch and it looks like it's working for me. 👍