Skip to content

Commit

Permalink
Merge branch 'master' into library
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlandon authored Nov 29, 2023
2 parents 656cf21 + 1e21686 commit fa41dc4
Show file tree
Hide file tree
Showing 13 changed files with 747 additions and 823 deletions.
1,018 changes: 631 additions & 387 deletions .dockerfile/root/.config/nushell/config.nu

Large diffs are not rendered by default.

80 changes: 48 additions & 32 deletions .dockerfile/root/.config/nushell/env.nu
Original file line number Diff line number Diff line change
@@ -1,62 +1,78 @@
# Nushell Environment Config File
#
# version = "0.85.0"

def create_left_prompt [] {
let path_segment = if (is-admin) {
$"(ansi red_bold)($env.PWD)"
} else {
$"(ansi green_bold)($env.PWD)"
}
let home = $nu.home-path

let dir = ([
($env.PWD | str substring 0..($home | str length) | str replace $home "~"),
($env.PWD | str substring ($home | str length)..)
] | str join)

let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
let path_segment = $"($path_color)($dir)"

$path_segment
$path_segment | str replace --all (char path_sep) $"($separator_color)/($path_color)"
}

def create_right_prompt [] {
# create a right prompt in magenta with green separators and am/pm underlined
let time_segment = ([
(date now | date format '%m/%d/%Y %r')
(ansi reset)
(ansi magenta)
(date now | format date '%x %X %p') # try to respect user's locale
] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" |
str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}")

let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
(ansi rb)
($env.LAST_EXIT_CODE)
] | str join)
} else { "" }

$time_segment
([$last_exit_code, (char space), $time_segment] | str join)
}

# Use nushell functions to define your right and left prompt
let-env PROMPT_COMMAND = { create_left_prompt }
let-env PROMPT_COMMAND_RIGHT = { create_right_prompt }
$env.PROMPT_COMMAND = {|| create_left_prompt }
# FIXME: This default is not implemented in rust code as of 2023-09-08.
$env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }

# The prompt indicators are environmental variables that represent
# the state of the prompt
let-env PROMPT_INDICATOR = { "" }
let-env PROMPT_INDICATOR_VI_INSERT = { ": " }
let-env PROMPT_INDICATOR_VI_NORMAL = { "" }
let-env PROMPT_MULTILINE_INDICATOR = { "::: " }
$env.PROMPT_INDICATOR = {|| "> " }
$env.PROMPT_INDICATOR_VI_INSERT = {|| ": " }
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "> " }
$env.PROMPT_MULTILINE_INDICATOR = {|| "::: " }

# Specifies how environment variables are:
# - converted from a string to a value on Nushell startup (from_string)
# - converted from a value back to a string when running external commands (to_string)
# Note: The conversions happen *after* config.nu is loaded
let-env ENV_CONVERSIONS = {
"PATH": {
from_string: { |s| $s | split row (char esep) | path expand -n }
to_string: { |v| $v | path expand -n | str join (char esep) }
}
"Path": {
from_string: { |s| $s | split row (char esep) | path expand -n }
to_string: { |v| $v | path expand -n | str join (char esep) }
}
$env.ENV_CONVERSIONS = {
"PATH": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
"Path": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
}

# Directories to search for scripts when calling source or use
#
# By default, <nushell-config-dir>/scripts is added
let-env NU_LIB_DIRS = [
($nu.config-path | path dirname | path join 'scripts')
$env.NU_LIB_DIRS = [
# FIXME: This default is not implemented in rust code as of 2023-09-06.
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts
]

# Directories to search for plugin binaries when calling register
#
# By default, <nushell-config-dir>/plugins is added
let-env NU_PLUGIN_DIRS = [
($nu.config-path | path dirname | path join 'plugins')
$env.NU_PLUGIN_DIRS = [
# FIXME: This default is not implemented in rust code as of 2023-09-06.
($nu.default-config-dir | path join 'plugins') # add <nushell-config-dir>/plugins
]

# To add entries to PATH (on Windows you might use Path), you can use the following pattern:
# let-env PATH = ($env.PATH | split row (char esep) | prepend '/some/path')
# $env.PATH = ($env.PATH | split row (char esep) | prepend '/some/path')
68 changes: 34 additions & 34 deletions .dockerfile/root/.config/nushell/starship.nu
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
let-env STARSHIP_SHELL = "nu"
let-env STARSHIP_SESSION_KEY = (random chars -l 16)
let-env PROMPT_MULTILINE_INDICATOR = (^/usr/local/bin/starship prompt --continuation)
# this file is both a valid
# - overlay which can be loaded with `overlay use starship.nu`
# - module which can be used with `use starship.nu`
# - script which can be used with `source starship.nu`
export-env { load-env {
STARSHIP_SHELL: "nu"
STARSHIP_SESSION_KEY: (random chars -l 16)
PROMPT_MULTILINE_INDICATOR: (
^/usr/bin/starship prompt --continuation
)
# Does not play well with default character module.
# TODO: Also Use starship vi mode indicators?
let-env PROMPT_INDICATOR = ""
# Does not play well with default character module.
# TODO: Also Use starship vi mode indicators?
PROMPT_INDICATOR: ""
let-env PROMPT_COMMAND = {
# jobs are not supported
let width = (term size).columns
^/usr/local/bin/starship prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
}

# Whether we can show right prompt on the last line
let has_rprompt_last_line_support = (version).version >= 0.71.0

# Whether we have config items
let has_config_items = (not ($env | get -i config | is-empty))

if $has_rprompt_last_line_support {
let config = if $has_config_items {
$env.config | upsert render_right_prompt_on_last_line true
} else {
{render_right_prompt_on_last_line: true}
PROMPT_COMMAND: {||
# jobs are not supported
(
^/usr/bin/starship prompt
--cmd-duration $env.CMD_DURATION_MS
$"--status=($env.LAST_EXIT_CODE)"
--terminal-width (term size).columns
)
}
{config: $config}
} else {
{ }
} | load-env

let-env PROMPT_COMMAND_RIGHT = {
if $has_rprompt_last_line_support {
let width = (term size).columns
^/usr/local/bin/starship prompt --right $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
} else {
''
config: ($env.config? | default {} | merge {
render_right_prompt_on_last_line: true
})

PROMPT_COMMAND_RIGHT: {||
(
^/usr/bin/starship prompt
--right
--cmd-duration $env.CMD_DURATION_MS
$"--status=($env.LAST_EXIT_CODE)"
--terminal-width (term size).columns
)
}
}
}}
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [rsteube]
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/rsteube/carapace
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/cache@v3
with:
key: linkcheck
path: docs/book/linkcheck

- name: "build docs"
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
permissions:
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
container: ghcr.io/rsteube/carapace
steps:
- name: shallow clone
uses: actions/checkout@v2
uses: actions/checkout@v4
if: "!startsWith(github.ref, 'refs/tags/')"

- name: deep clone
uses: actions/checkout@v2
uses: actions/checkout@v4
if: startsWith(github.ref, 'refs/tags/')
with:
fetch-depth: 0
Expand All @@ -29,13 +29,22 @@ jobs:
run: go generate ./...

- name: Test
run: go test -v ./...
run: mkdir .cover && CARAPACE_COVERDIR="$(pwd)/.cover" go test -v -coverpkg ./... -coverprofile=unit.cov ./... ./example-nonposix/...

- name: Bench
run: go test -bench ./...

- name: Convert coverage
run: go tool covdata textfmt -i .cover/ -o integration.cov

- name: Filter coverage
run: sed -i '/^github.com\/rsteube\/carapace\/third_party/d' unit.cov integration.cov

- name: "Check formatting"
run: '[ "$(gofmt -d -s . | tee -a /dev/stderr)" = "" ]'

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v5
if: startsWith(github.ref, 'refs/tags/')
with:
version: latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
with:
go-version: '1.17'
cache: false
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
example/example
caraparse/caraparse
docs/book
example/cmd/_test_files/*.txt
example/example
example-nonposix/example-nonposix
integration.cov
unit.cov
.vscode
2 changes: 1 addition & 1 deletion compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (d compDirective) ToA(values ...string) Action {
var action Action
switch {
case d.matches(cobra.ShellCompDirectiveError):
return ActionMessage("an error occurred")
return ActionMessage("an error occured")
case d.matches(cobra.ShellCompDirectiveFilterDirs):
switch len(values) {
case 0:
Expand Down
Loading

0 comments on commit fa41dc4

Please sign in to comment.