Comments (3)
Hey @ChampiYann! Great to see you diving into the depths of pkgx and p10k. I remember our last dance around the digital bonfire. How’s the coding journey treating you this time?
To display the (+pkg)
prefix in your command prompt with a p10k setup, you can utilize the output from the internal.activate
case in your app.ts
file. Specifically, the line that logs the activated packages with a +
prefix before their names:
console.error(`%s %s`, blurple('env'), pkgs.map(x => `+${utils.pkg.str(x)}`).join(' '))
This line of code formats the activated packages to have a +
prefix and joins them with a space. To integrate this with a p10k command prompt setup, you would need to capture this output and set it as part of your prompt. This can be done by modifying your .p10k.zsh
or equivalent configuration file to execute a command that triggers this specific functionality in your app.ts
, capturing its output, and then including that output in your prompt.
For example, if you had a way to execute your application such that it only performed the internal.activate
action, you might add something like this to your .p10k.zsh
:
function pkgx_env_prompt() {
# Assuming `app.ts` can be executed to just output the activated environments
local pkgx_output="$(deno run --allow-env src/app.ts --internal-activate)"
[[ -n "$pkgx_output" ]] && echo "$pkgx_output"
}
# Then in your POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS or POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
# add a custom element that calls this function
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(... pkgx_env_prompt ...)
This is a hypothetical example. You would need to adjust the execution command (deno run --allow-env src/app.ts --internal-activate
) to match how your application should be called to output only the activated environments as seen in the internal.activate
case in your app.ts
.
Remember, for this to work:
- Ensure your application can be executed in a way that it only performs the
internal.activate
action and outputs the format seen in the provided code snippet. - Adjust the shell function and p10k configuration according to how your environment and application are set up.
Regarding your question about the internal.activate
function in the pkgx codebase, it is designed to be invoked programmatically, as it is an exported asynchronous function that takes a directory path (dir
) and an options object as its parameters. The options object includes a powder
property, which is an array of PackageRequirement
, and a logger
property, which is of type Logger
. This function is not directly tied to a specific command-line command within the provided context. Instead, it is meant to be called by other parts of the pkgx
codebase or potentially by external scripts/modules that import and use this functionality.
The function performs several key operations:
- Validates the provided directory path.
- Constructs a development environment by installing packages and setting up environment variables.
- Handles user-supplied environment variables.
- Generates shell commands for activating and deactivating the development environment.
Given the context, to invoke this function, one would need to call it from another TypeScript or JavaScript file, passing the required dir
and options object. There's no indication of a specific command-line interface command provided in the context that would directly trigger this function. It's part of the internal API of the pkgx
package, meant for programmatic use.
Example of how it might be invoked in code (not directly from the provided context but based on the function signature):
import activate from 'src/modes/internal.activate.ts';
// Example directory and options
const dir = new Path('/path/to/directory');
const options = {
powder: [{ /* PackageRequirement objects */ }],
logger: {/* Logger object */}
};
// Invoke the function
activate(dir, options).then(() => {
console.log('Activation complete.');
}).catch(error => {
console.error('Activation failed:', error);
});
This example assumes the existence of Path
, PackageRequirement
, and Logger
types or classes that are compatible with the activate
function's parameters.
The structure of the PackageRequirement
object that is passed as part of the options to the internal.activate
function in the pkgx codebase, based on the provided context, includes the following properties:
project
: Derived fromprojects[0].project
.constraint
: Derived fromrawpkg.constraint
.update
: A boolean value that is optionally added based on the presence of@latest
in the input string and theopts.latest
flag.
Therefore, the PackageRequirement
object structure is:
{
project: string;
constraint: string;
update?: boolean;
}
I hope this helps! If you have any more questions, feel free to ask.
Sources
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
from pkgx.
That's pretty cool, @ChampiYann ; we'll have to find a place in the docs for that.
from pkgx.
I fixed it in a different and, I guess, more correct way by using the PKGX_POWDER and PKGX_PKGENV environment variables.
This is the p10k prompt function I came up with:
function prompt_pkgx() {
# Check if POWDER and PKGENV variables are set
if [ -z "$PKGX_POWDER" ] || [ -z "$PKGX_PKGENV" ]; then
return
fi
# Variable to store matched values
matched_values=""
# Loop through each value in POWDER
for powder_value in ${(s: :)PKGX_POWDER}; do
# Loop through each value in PKGENV
for pkgenv_value in ${(s: :)PKGX_PKGENV}; do
# Check if PKGENV value starts with POWDER value
if [[ "$pkgenv_value" == "$powder_value"* ]]; then
# Append the matched value to the variable
matched_values="$matched_values $pkgenv_value"
fi
done
done
p10k segment -i PACKAGE_ICON -t "$matched_values" -r
}
The function first checks if the variables exit.
If so, it'll loop over PKGX_POWDER and look for matches in PKGX_PKGENV in order to get de version of the used powder.
It then creates a segment with those pkg env values.
Of course, with p10k you can put the segment anywhere you want. I just decided to add it above the prompt line on the right.
from pkgx.
Related Issues (20)
- Pkgx sometimes "forgets" to provide a dependency? HOT 3
- `pkgx uninstall` fails if pantry is not downloaded yet HOT 1
- `pkgx install` does not expand programs templates HOT 1
- pipx error while loading shared libraries: libpython3.11.so.1.0 HOT 6
- Allow custom installation location HOT 1
- [dev] Feature Request: Support `packageManager` in `package.json`
- Command not found behavior, exit faster?
- warn: parse failure: valkey.io HOT 3
- Where is markdown blocks execition engine? HOT 14
- pkgx and systemd unit HOT 8
- Are you sure macOS x86-64 binaries in GitHub releases are x86-64? HOT 5
- `pkgx --sync` on `main` never finishes if the pantry repo was not updated in the last 24 hours HOT 6
- `pkgx --sync` on `main` takes around 1 minute while in `v1.1.6` takes 1 second HOT 1
- Need equivalent of brew search and brew list command
- Error when working offline HOT 6
- x509 certificate trust error in pkgx docker container HOT 4
- unexpected error error sending request...invalid peer certificate: UnknownIssuer HOT 3
- Can't use yarn in context of another command HOT 7
- Can we get more scalable programs on PKGX? HOT 1
- `pkgx install` should overwrite existing versions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pkgx.