09a81492d100baa5b6e86ee4ac6dd7847535cf88
[webi-installers/.git] / pathman / pathman.bash
1 #!/bin/bash
2
3 # title: Pathman
4 # homepage: https://git.rootprojects.org/root/pathman
5 # tagline: cross-platform PATH management for bash, zsh, fish, cmd.exe, and PowerShell
6 # description: |
7 #   Manages PATH on various OSes and shells
8 #     - Mac, Windows, Linux
9 #     - Bash, Zsh, Fish
10 #     - Command, Powershell
11 # examples: |
12 #   ```bash
13 #   pathman add ~/.local/bin
14 #   ```
15 #   <br/>
16 #
17 #   ```bash
18 #   pathman remove ~/.local/bin
19 #   ```
20 #   <br/>
21 #
22 #   ```bash
23 #   pathman list
24 #   ```
25
26
27 set -e
28 set -u
29
30 # Get arch envs, etc
31 my_url="https://rootprojects.org/pathman/dist/$(uname -s)/$(uname -m)/pathman"
32 curl -fsSL "$my_url" -o pathman
33 echo ""
34 # Make executable
35 chmod +x ./pathman
36 # Move to ~/.local/bin
37 mkdir -p ~/.local/bin
38 mv ./pathman ~/.local/bin
39
40 # Test if in PATH
41 set +e
42 my_pathman=$(command -v pathman)
43 set -e
44 if [ -n "$my_pathman" ]; then
45         if [ "$my_pathman" != "$HOME/.local/bin/pathman" ]; then
46                 echo "a pathman installation (which make take precedence) exists at:"
47                 echo "    $my_pathman"
48                 echo ""
49         fi
50 fi
51
52 # add to ~/.local/bin to PATH even if pathman is elsewhere
53 # TODO pathman needs silent option and debug output (quiet "already exists" output)
54 ~/.local/bin/pathman add ~/.local/bin # > /dev/null 2> /dev/null
55 # TODO inform user to add to path, apart from pathman?