Skip to content

Commit

Permalink
README: Add additional tips for scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
andsens committed Nov 21, 2023
1 parent ff29638 commit 3daee46
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and global installation for user- or system-wide usage.
- [Transactionality](#transactionality)
- [Including dependencies](#including-dependencies)
- [Checking dependencies](#checking-dependencies)
- [Additional tips for scripting](#additional-tips-for-scripting)
- [upkg.json](#upkg-json)
- [dependencies](#dependencies)
- [files](#files)
Expand Down Expand Up @@ -209,9 +210,6 @@ my_fn() {
my_fn "$@"
```

Use `upkg root -g` to get the path to the global installation instead of
hardcoding `$HOME/.local/lib/upkg` or `/usr/local/lib/upkg`.

### Checking dependencies

For scripts that you don't install via μpkg, checking whether dependencies are
Expand All @@ -226,6 +224,24 @@ PKGROOT=$(upkg root "${BASH_SOURCE[0]}")
})
```

### Additional tips for scripting

When creating scripts not installed via upkg, use `upkg root -g` to get the path
to the global installation instead of hardcoding `$HOME/.local/lib/upkg` or
`/usr/local/lib/upkg`.

Use `local pkgroot; pkgroot=$(upkg root "${BASH_SOURCE[0]}")` inside your function
if you are building a library (as opposed to a command) to avoid `$PKGROOT`
being overwritten by external code.

You only need to specify `# shellcheck source-path=` if your script is not
located in `$pkgroot` (`source-path` is `./` by default).

If you are calling scripts from the same package consider using
[path-tools](https://github.com/orbit-online/path-tools) to avoid prepending
the same `.upkg/bin` PATH multiple times (i.e. use
`PATH=$("$pkgroot/.upkg/.bin/path_prepend" "$pkgroot/.upkg/.bin")` instead).

### upkg.json

`upkg.json` has no package name, version or description.
Expand Down

0 comments on commit 3daee46

Please sign in to comment.