From 3fa0923b17151c5c7a06fb305813c330b1295301 Mon Sep 17 00:00:00 2001 From: amtoine Date: Wed, 31 Jan 2024 18:32:13 +0100 Subject: [PATCH 1/2] add a new `dotfiles.nu` with `gm cfg` commands --- .../nu-git-manager-sugar/dotfiles.nu | 60 +++++++++++++++++++ .../nu-git-manager-sugar/mod.nu | 1 + 2 files changed, 61 insertions(+) create mode 100644 pkgs/nu-git-manager-sugar/nu-git-manager-sugar/dotfiles.nu diff --git a/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/dotfiles.nu b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/dotfiles.nu new file mode 100644 index 0000000..5926de5 --- /dev/null +++ b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/dotfiles.nu @@ -0,0 +1,60 @@ +# the `dotfiles` module ships the `gm cfg` command +# +# the goal of `gm cfg` is to provide tools to interact with dotfiles managed +# through a _bare_ repo. + +# manage dotfiles from anywhere +# +# this command is basically a thin wrapper around the `git` command... but for +# _bare_ dotfiles. +# +# `gm cfg` requires the following environment variables to be defined +# - `DOTFILES_GIT_DIR`: the location where to find the _bare_ repo of the +# dotfiles, e.g. `~/documents/repos/dotfiles` or something like +# `$env.GIT_REPOS_HOME | path join "github.com" "amtoine" "dotfiles"` +# - `DOTFILES_WORKTREE`: the actual worktree where the dotfiles live, e.g. the +# home directory +# +# # Examples +# ```nushell +# # list all the files that are tracked as dotfiles +# gm cfg ls-files ~ +# ``` +# --- +# ```nushell +# # get the current status of the dotfiles in short format +# gm status --short +# ``` +export def --wrapped "gm cfg" [...args] { + ^git --git-dir $env.DOTFILES_GIT_DIR --work-tree $env.DOTFILES_WORKTREE ...$args +} + +def "ansi cmd" []: string -> string { + $"`(ansi default_dimmed)($in)(ansi reset)`" +} + +# edit any config file tracked as dotfiles +# +# this command will +# - let you fuzzy search amongst all the dotfiles +# - switch to the parent directory of the selected dotfile +# - open the selected dotfile in `$env.EDITOR` +export def "gm cfg edit" [] { + let git_options = [ + --git-dir $env.DOTFILES_GIT_DIR + --work-tree $env.DOTFILES_WORKTREE + ] + + let prompt = $"choose a config file to (ansi cyan_bold)edit(ansi reset):" + let choice = ^git ...$git_options ls-files --full-name $env.DOTFILES_WORKTREE + | lines + | input list --fuzzy $prompt + if ($choice | is-empty) { + return + } + + let config_file = $env.DOTFILES_WORKTREE | path join $choice + + cd ($config_file | path dirname) + ^$env.EDITOR $config_file +} diff --git a/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/mod.nu b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/mod.nu index 21884c9..74c982f 100644 --- a/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/mod.nu +++ b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/mod.nu @@ -9,3 +9,4 @@ module completions.nu export module extra.nu export module git/ export module github.nu +export module dotfiles.nu From 548b664f007cc7c00abe7cfdf829c798a17aab29 Mon Sep 17 00:00:00 2001 From: amtoine Date: Wed, 31 Jan 2024 18:49:06 +0100 Subject: [PATCH 2/2] generate the doc --- docs/index.md | 2 ++ .../dotfiles/gm-cfg-edit.md | 15 +++++++++ docs/nu-git-manager-sugar/dotfiles/gm-cfg.md | 31 +++++++++++++++++++ docs/nu-git-manager-sugar/dotfiles/index.md | 7 +++++ docs/nu-git-manager-sugar/index.md | 1 + 5 files changed, 56 insertions(+) create mode 100644 docs/nu-git-manager-sugar/dotfiles/gm-cfg-edit.md create mode 100644 docs/nu-git-manager-sugar/dotfiles/gm-cfg.md create mode 100644 docs/nu-git-manager-sugar/dotfiles/index.md diff --git a/docs/index.md b/docs/index.md index 7118052..1a9c839 100644 --- a/docs/index.md +++ b/docs/index.md @@ -11,6 +11,8 @@ - [`gm squash-forks`](nu-git-manager/gm-squash-forks.md) - [`gm status`](nu-git-manager/gm-status.md) - [`gm update-cache`](nu-git-manager/gm-update-cache.md) +- [`gm cfg`](nu-git-manager-sugar/dotfiles/gm-cfg.md) +- [`gm cfg edit`](nu-git-manager-sugar/dotfiles/gm-cfg-edit.md) - [`gm report`](nu-git-manager-sugar/extra/gm-report.md) - [`gm repo bisect`](nu-git-manager-sugar/git/gm-repo-bisect.md) - [`gm repo branch interactive-delete`](nu-git-manager-sugar/git/gm-repo-branch-interactive-delete.md) diff --git a/docs/nu-git-manager-sugar/dotfiles/gm-cfg-edit.md b/docs/nu-git-manager-sugar/dotfiles/gm-cfg-edit.md new file mode 100644 index 0000000..df861c2 --- /dev/null +++ b/docs/nu-git-manager-sugar/dotfiles/gm-cfg-edit.md @@ -0,0 +1,15 @@ +# `gm cfg edit` from `nu-git-manager-sugar dotfiles` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/dotfiles.nu#L42)) +edit any config file tracked as dotfiles + +this command will +- let you fuzzy search amongst all the dotfiles +- switch to the parent directory of the selected dotfile +- open the selected dotfile in `$env.EDITOR` + +## Parameters + + +## Signatures +| input | output | +| ----- | ------ | +| `any` | `any` | diff --git a/docs/nu-git-manager-sugar/dotfiles/gm-cfg.md b/docs/nu-git-manager-sugar/dotfiles/gm-cfg.md new file mode 100644 index 0000000..fee9f3b --- /dev/null +++ b/docs/nu-git-manager-sugar/dotfiles/gm-cfg.md @@ -0,0 +1,31 @@ +# `gm cfg` from `nu-git-manager-sugar dotfiles` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/dotfiles.nu#L28)) +manage dotfiles from anywhere + +this command is basically a thin wrapper around the `git` command... but for +_bare_ dotfiles. + +`gm cfg` requires the following environment variables to be defined +- `DOTFILES_GIT_DIR`: the location where to find the _bare_ repo of the + dotfiles, e.g. `~/documents/repos/dotfiles` or something like + `$env.GIT_REPOS_HOME | path join "github.com" "amtoine" "dotfiles"` +- `DOTFILES_WORKTREE`: the actual worktree where the dotfiles live, e.g. the + home directory + +# Examples +```nushell +# list all the files that are tracked as dotfiles +gm cfg ls-files ~ +``` +--- +```nushell +# get the current status of the dotfiles in short format +gm status --short +``` + +## Parameters + + +## Signatures +| input | output | +| ----- | ------ | +| `any` | `any` | diff --git a/docs/nu-git-manager-sugar/dotfiles/index.md b/docs/nu-git-manager-sugar/dotfiles/index.md new file mode 100644 index 0000000..244dc3d --- /dev/null +++ b/docs/nu-git-manager-sugar/dotfiles/index.md @@ -0,0 +1,7 @@ +# Module `nu-git-manager-sugar dotfiles` +## Description +the `dotfiles` module ships the `gm cfg` command + +## Commands +- [`gm cfg`](gm-cfg.md) +- [`gm cfg edit`](gm-cfg-edit.md) \ No newline at end of file diff --git a/docs/nu-git-manager-sugar/index.md b/docs/nu-git-manager-sugar/index.md index 230ba57..9c763f6 100644 --- a/docs/nu-git-manager-sugar/index.md +++ b/docs/nu-git-manager-sugar/index.md @@ -7,6 +7,7 @@ on top. no commands ## Submodules +- [`dotfiles`](dotfiles/index.md) - [`extra`](extra/index.md) - [`git`](git/index.md) - [`github`](github/index.md) \ No newline at end of file