mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 15:17:47 +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:
parent
bdfed700a4
commit
53108cd068
1 changed files with 454 additions and 459 deletions
|
@ -2,13 +2,13 @@
|
||||||
# An opinionated Git prompt for Nushell, styled after posh-git
|
# An opinionated Git prompt for Nushell, styled after posh-git
|
||||||
#
|
#
|
||||||
# Quick Start:
|
# Quick Start:
|
||||||
# - Download this script (panache-git.nu)
|
# - Download this file (panache-git.nu)
|
||||||
# - In your Nushell config:
|
# - 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
|
# - Set panache-git as your prompt command
|
||||||
# - Disable the separate prompt indicator by setting it to an empty string
|
# - Disable the separate prompt indicator by setting it to an empty string
|
||||||
# - For example, with this script in your home directory:
|
# - For example, with this file in your home directory:
|
||||||
# source ~/panache-git.nu
|
# use ~/panache-git.nu panache-git
|
||||||
# let-env PROMPT_COMMAND = { panache-git }
|
# let-env PROMPT_COMMAND = { panache-git }
|
||||||
# let-env PROMPT_INDICATOR = { "" }
|
# let-env PROMPT_INDICATOR = { "" }
|
||||||
# - Restart Nushell
|
# - Restart Nushell
|
||||||
|
@ -16,11 +16,14 @@
|
||||||
# For more documentation or to file an issue, see https://github.com/ehdevries/panache-git
|
# 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
|
# An opinionated Git prompt for Nushell, styled after posh-git
|
||||||
module panache-plumbing {
|
export def panache-git [] {
|
||||||
|
let prompt = ($'(current-dir) (repo-styled)' | str trim)
|
||||||
|
$'($prompt)> '
|
||||||
|
}
|
||||||
|
|
||||||
# Get the current directory with home abbreviated
|
# Get the current directory with home abbreviated
|
||||||
export def "panache-git dir" [] {
|
def current-dir [] {
|
||||||
let current_dir = ($env.PWD)
|
let current_dir = ($env.PWD)
|
||||||
|
|
||||||
let current_dir_relative_to_home = (
|
let current_dir_relative_to_home = (
|
||||||
|
@ -39,7 +42,7 @@ module panache-plumbing {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get repository status as structured data
|
# 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 in_git_repo = (do --ignore-errors { git rev-parse --abbrev-ref HEAD } | is-empty | nope)
|
||||||
|
|
||||||
let status = (if $in_git_repo {
|
let status = (if $in_git_repo {
|
||||||
|
@ -242,8 +245,8 @@ module panache-plumbing {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get repository status as a styled string
|
# Get repository status as a styled string
|
||||||
export def "panache-git styled" [] {
|
def repo-styled [] {
|
||||||
let status = (panache-git structured)
|
let status = (repo-structured)
|
||||||
|
|
||||||
let is_local_only = ($status.tracking_upstream_branch != true)
|
let is_local_only = ($status.tracking_upstream_branch != true)
|
||||||
|
|
||||||
|
@ -466,11 +469,3 @@ module panache-plumbing {
|
||||||
] {
|
] {
|
||||||
$'!($conflicts)' | red
|
$'!($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)> '
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue