1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00

Convert panache-git from script to module (#292)

In Nushell 0.68, the `source` command has been deprecated.
Going forward, the way to utilize custom commands is
to put them into a module and import them with `use`.

This means that `panache-git.nu` had to be converted
from a script to a module so that the main prompt command
could be imported by a user's Nushell environment config.
This commit is contained in:
Edward DeVries 2022-09-07 17:52:45 -04:00 committed by GitHub
parent bdfed700a4
commit 53108cd068
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,13 +2,13 @@
# An opinionated Git prompt for Nushell, styled after posh-git
#
# Quick Start:
# - Download this script (panache-git.nu)
# - Download this file (panache-git.nu)
# - In your Nushell config:
# - Source this script
# - Import the panache-git command from the panache-git.nu module file
# - Set panache-git as your prompt command
# - Disable the separate prompt indicator by setting it to an empty string
# - For example, with this script in your home directory:
# source ~/panache-git.nu
# - For example, with this file in your home directory:
# use ~/panache-git.nu panache-git
# let-env PROMPT_COMMAND = { panache-git }
# let-env PROMPT_INDICATOR = { "" }
# - Restart Nushell
@ -16,11 +16,14 @@
# For more documentation or to file an issue, see https://github.com/ehdevries/panache-git
# Internal commands for building up the panache-git shell prompt
module panache-plumbing {
# An opinionated Git prompt for Nushell, styled after posh-git
export def panache-git [] {
let prompt = ($'(current-dir) (repo-styled)' | str trim)
$'($prompt)> '
}
# Get the current directory with home abbreviated
export def "panache-git dir" [] {
def current-dir [] {
let current_dir = ($env.PWD)
let current_dir_relative_to_home = (
@ -39,7 +42,7 @@ module panache-plumbing {
}
# Get repository status as structured data
export def "panache-git structured" [] {
def repo-structured [] {
let in_git_repo = (do --ignore-errors { git rev-parse --abbrev-ref HEAD } | is-empty | nope)
let status = (if $in_git_repo {
@ -242,8 +245,8 @@ module panache-plumbing {
}
# Get repository status as a styled string
export def "panache-git styled" [] {
let status = (panache-git structured)
def repo-styled [] {
let status = (repo-structured)
let is_local_only = ($status.tracking_upstream_branch != true)
@ -466,11 +469,3 @@ module panache-plumbing {
] {
$'!($conflicts)' | red
}
}
# An opinionated Git prompt for Nushell, styled after posh-git
def panache-git [] {
use panache-plumbing *
let prompt = ($'(panache_git dir) (panache-git styled)' | str trim)
$'($prompt)> '
}