Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new dotfiles module to sugar with gm cfg commands #177

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions docs/nu-git-manager-sugar/dotfiles/gm-cfg-edit.md
Original file line number Diff line number Diff line change
@@ -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` |
31 changes: 31 additions & 0 deletions docs/nu-git-manager-sugar/dotfiles/gm-cfg.md
Original file line number Diff line number Diff line change
@@ -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` |
7 changes: 7 additions & 0 deletions docs/nu-git-manager-sugar/dotfiles/index.md
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions docs/nu-git-manager-sugar/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
60 changes: 60 additions & 0 deletions pkgs/nu-git-manager-sugar/nu-git-manager-sugar/dotfiles.nu
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions pkgs/nu-git-manager-sugar/nu-git-manager-sugar/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ module completions.nu
export module extra.nu
export module git/
export module github.nu
export module dotfiles.nu
Loading