Add perl-info function
This commit is contained in:
parent
29593e62e3
commit
2205869f03
2 changed files with 48 additions and 0 deletions
|
@ -51,6 +51,24 @@ Aliases
|
||||||
- `plbu` uninstalls a Perl version.
|
- `plbu` uninstalls a Perl version.
|
||||||
- `plbx` temporarily sets the Perl version to use.
|
- `plbx` temporarily sets the Perl version to use.
|
||||||
|
|
||||||
|
Functions
|
||||||
|
---------
|
||||||
|
|
||||||
|
- `perl-info` exposes information about the Perl environment via the
|
||||||
|
`$perl_info` associative array.
|
||||||
|
|
||||||
|
Theming
|
||||||
|
-------
|
||||||
|
|
||||||
|
To display the name of the currach Perl version in a prompt, define the
|
||||||
|
following style in the `prompt_name_setup` function.
|
||||||
|
|
||||||
|
# %v - perl version.
|
||||||
|
zstyle ':prezto:module:perl:info:version' format 'version:%v'
|
||||||
|
|
||||||
|
Then add `$perl_info[version]` to `$PROMPT` or `$RPROMPT` and call
|
||||||
|
`perl-info` in the `prompt_name_precmd` hook function.
|
||||||
|
|
||||||
Authors
|
Authors
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
30
modules/perl/functions/perl-info
Normal file
30
modules/perl/functions/perl-info
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#
|
||||||
|
# Exposes information about the Perl environment via the $perl_info associative
|
||||||
|
# array.
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# JINNOUCHI Yasushi <delphinus@remora.cx>
|
||||||
|
#
|
||||||
|
|
||||||
|
local version
|
||||||
|
local version_format
|
||||||
|
local version_formatted
|
||||||
|
|
||||||
|
# Clean up previous $perl_info.
|
||||||
|
unset perl_info
|
||||||
|
typeset -gA perl_info
|
||||||
|
|
||||||
|
if (( $+commands[perlbrew] )); then
|
||||||
|
version=${${(F)${(f)"$(perlbrew list)"}:# *}[(w)2]}
|
||||||
|
elif (( $+commands[plenv] )); then
|
||||||
|
version=$(plenv version-name)
|
||||||
|
elif (( $+commands[perl] )); then
|
||||||
|
version=$(perl -e 'printf "%vd", $^V')
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Format version.
|
||||||
|
if [[ -n "$version" ]]; then
|
||||||
|
zstyle -s ':prezto:module:perl:info:version' format 'version_format'
|
||||||
|
zformat -f version_formatted "$version_format" "v:$version"
|
||||||
|
perl_info[version]="$version_formatted"
|
||||||
|
fi
|
Loading…
Add table
Reference in a new issue