Skip to content

Commit 1f67827

Browse files
committed
adopt zsh4humans
1 parent 3f33028 commit 1f67827

File tree

4 files changed

+65
-63
lines changed

4 files changed

+65
-63
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ See [here for an example config](./settle.yaml).
2222
* cleans up packages no longer specified
2323

2424
**Zsh Support**:
25-
* plugins using zinit
25+
* installing zsh4humans's .zshenv
2626
* configuring history size and history sharing
2727
* variables
2828
* aliases

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
set -euo pipefail
2929

30-
version=0.0.13 # TODO integrate with releases.
30+
version=0.0.14 # TODO integrate with releases.
3131

3232
settle_base=$(pwd)
3333

internal/zsh/zsh.go

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@ package zsh
33
import (
44
"context"
55
"fmt"
6+
"io"
7+
"net/http"
68
"os"
79
"path/filepath"
810
"strconv"
911
"strings"
1012

11-
"github.com/go-git/go-git/v5"
1213
"golang.org/x/exp/slices"
1314
)
1415

1516
type Zsh struct {
16-
Zinit []string `json:"zinit"`
17-
History struct {
17+
Zsh4Humans bool `json:"zsh4humans"`
18+
History struct {
1819
Size int `json:"size"`
1920
ShareHistory bool `json:"share_history"`
2021
IncAppend bool `json:"inc_append"`
2122
IgnoreAllDups bool `json:"ignore_all_dups"`
2223
IgnoreSpace bool `json:"ignore_space"`
2324
} `json:"history"`
24-
Paths []string `json:"paths"`
25-
Variables []KV `json:"variables"`
26-
Aliases []KV `json:"aliases"`
27-
Functions []KV `json:"functions"`
28-
ExtraPrefix string `json:"extra_prefix"`
29-
ExtraSuffix string `json:"extra_suffix"`
25+
Paths []string `json:"paths"`
26+
Variables []KV `json:"variables"`
27+
Aliases []KV `json:"aliases"`
28+
Functions []KV `json:"functions"`
29+
Prefix string `json:"prefix"`
30+
Suffix string `json:"suffix"`
3031
}
3132

3233
type KV struct {
@@ -39,7 +40,7 @@ func (z *Zsh) Ensure(ctx context.Context) error {
3940
return nil
4041
}
4142

42-
if err := z.ensureZinit(ctx); err != nil {
43+
if err := z.ensureZsh4Humans(ctx); err != nil {
4344
return fmt.Errorf("error ensuring zinit: %w", err)
4445
}
4546
home, err := os.UserHomeDir()
@@ -53,32 +54,44 @@ func (z *Zsh) Ensure(ctx context.Context) error {
5354
return nil
5455
}
5556

56-
const (
57-
zinitURL = "https://raw.githubusercontent.com/zdharma-continuum/zinit/master/zinit.zsh"
58-
)
59-
60-
func (z *Zsh) ensureZinit(ctx context.Context) error {
61-
if len(z.Zinit) == 0 {
57+
func (z *Zsh) ensureZsh4Humans(ctx context.Context) error {
58+
if !z.Zsh4Humans {
6259
return nil
6360
}
6461

6562
home, err := os.UserHomeDir()
6663
if err != nil {
6764
return fmt.Errorf("unable to determine home dir: %w", err)
6865
}
69-
dstPath := filepath.Join(home, ".zinit", "bin", "zinit.zsh")
66+
zshenv := filepath.Join(home, ".zshenv")
7067

71-
_, err = os.Stat(dstPath)
68+
_, err = os.Stat(zshenv)
7269
if err == nil {
7370
return nil // file already exists
7471
} else if err != nil && !os.IsNotExist(err) {
7572
return err
7673
}
7774

78-
fmt.Println("installing Zinit")
79-
_, err = git.PlainCloneContext(ctx, filepath.Join(home, ".zinit", "bin"), false, &git.CloneOptions{URL: "https://github.com/zdharma-continuum/zinit.git"})
75+
fmt.Println("writing zsh4humans .zshenv file")
76+
url := "https://raw.githubusercontent.com/romkatv/zsh4humans/v5/.zshenv"
77+
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
78+
if err != nil {
79+
return fmt.Errorf("building request to fetch zsh4humans .zshenv: %w", err)
80+
}
81+
resp, err := http.DefaultClient.Do(req)
82+
if err != nil {
83+
return fmt.Errorf("fetching zsh4humans .zshenv: %w", err)
84+
}
85+
defer resp.Body.Close()
86+
body, err := io.ReadAll(resp.Body)
8087
if err != nil {
81-
return fmt.Errorf("error cloning zinit: %w", err)
88+
return fmt.Errorf("reading zsh4humans .zshenv body: %w", err)
89+
}
90+
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusBadRequest {
91+
return fmt.Errorf("bad response fetching %s (%d): %s", url, resp.StatusCode, string(body))
92+
}
93+
if err := os.WriteFile(zshenv, body, 0o644); err != nil {
94+
return fmt.Errorf("writing .zshenv: %w", err)
8295
}
8396
return nil
8497
}
@@ -87,13 +100,7 @@ func (z *Zsh) String() string {
87100
var sb strings.Builder
88101

89102
// extra prefix
90-
sb.WriteString(z.ExtraPrefix)
91-
sb.WriteString("\n")
92-
93-
// zinit
94-
for _, line := range z.Zinit {
95-
sb.WriteString(fmt.Sprintf("zinit %s\n", line))
96-
}
103+
sb.WriteString(z.Prefix)
97104
sb.WriteString("\n")
98105

99106
// history
@@ -147,7 +154,7 @@ func (z *Zsh) String() string {
147154
sb.WriteString("\n")
148155

149156
// extra suffix
150-
sb.WriteString(z.ExtraSuffix)
157+
sb.WriteString(z.Suffix)
151158
sb.WriteString("\n")
152159
return sb.String()
153160
}

settle.yaml

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,19 @@ brew:
9999
- vlc
100100

101101
zsh:
102-
zinit:
103-
- ice pick=async.zsh src=pure.zsh
104-
- light sindresorhus/pure
105-
- light zdharma-continuum/fast-syntax-highlighting
106-
- snippet OMZ::plugins/fasd/fasd.plugin.zsh
107-
- snippet OMZ::plugins/fzf/fzf.plugin.zsh
102+
zsh4humans: true
108103
history:
109104
size: 50000
110105
share_history: true
111106
inc_append: true
112107
ignore_all_dups: true
113108
ignore_space: true
109+
paths:
110+
- $HOME/go/bin
111+
- $HOME/bin
114112
variables:
115113
- {name: DOTFILES, value: "$HOME/src/danielmmetz/dotfiles"}
116114
- {name: EDITOR, value: "nvim"}
117-
- {name: PATH, value: "$PATH:$HOME/go/bin:$HOME/bin"}
118115
- {name: HOMEBREW_NO_AUTO_UPDATE, value: "1"}
119116
aliases:
120117
- {name: cat, value: "bat"}
@@ -126,29 +123,27 @@ zsh:
126123
- {name: vim, value: "nvim"}
127124
- {name: vimrc, value: "nvim $DOTFILES/nvim.yaml"}
128125
- {name: zshrc, value: "nvim $DOTFILES/settle.yaml"}
129-
extra_prefix: |
130-
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
131-
echo "Installing DHARMA Initiative Plugin Manager (zdharma-continuum/zinit)…"
132-
mkdir -p "$HOME/.zinit" && chmod g-rwX "$HOME/.zinit"
133-
git clone https://github.com/zdharma-continuum/zinit "$HOME/.zinit/bin" && \
134-
echo "Installation successful" || \
135-
echo "The clone has failed."
136-
fi
126+
prefix: |
127+
zstyle ':z4h:' auto-update 'no'
128+
zstyle ':z4h:bindkey' keyboard 'mac'
129+
zstyle ':z4h:' start-tmux no
130+
zstyle ':z4h:' term-shell-integration 'yes'
131+
zstyle ':z4h:autosuggestions' forward-char 'accept'
132+
zstyle ':z4h:fzf-complete' recurse-dirs 'no'
133+
zstyle ':z4h:direnv' enable 'no'
134+
zstyle ':z4h:direnv:success' notify 'yes'
135+
zstyle ':z4h:ssh:*' enable 'no'
136+
# Anything that requires I/O must be done at this point.
137+
z4h init || return
137138
138-
source "$HOME/.zinit/bin/zinit.zsh"
139-
autoload -Uz _zinit
140-
(( ${+_comps} )) && _comps[zinit]=_zinit
141-
extra_suffix: |
142-
_direnv_hook() {
143-
trap -- '' SIGINT;
144-
eval "$("/usr/local/bin/direnv" export zsh)";
145-
trap - SIGINT;
146-
}
147-
typeset -ag precmd_functions;
148-
if [[ -z ${precmd_functions[(r)_direnv_hook]} ]]; then
149-
precmd_functions=( _direnv_hook ${precmd_functions[@]} )
150-
fi
151-
typeset -ag chpwd_functions;
152-
if [[ -z ${chpwd_functions[(r)_direnv_hook]} ]]; then
153-
chpwd_functions=( _direnv_hook ${chpwd_functions[@]} )
154-
fi
139+
z4h bindkey undo Ctrl+/ Shift+Tab # undo the last command line change
140+
z4h bindkey redo Option+/ # redo the last undone command line change
141+
142+
z4h bindkey z4h-cd-back Shift+Left # cd into the previous directory
143+
z4h bindkey z4h-cd-forward Shift+Right # cd into the next directory
144+
z4h bindkey z4h-cd-up Shift+Up # cd into the parent directory
145+
z4h bindkey z4h-cd-down Shift+Down # cd into a child directory
146+
147+
autoload -Uz zmv
148+
suffix: |
149+
# hello everybody

0 commit comments

Comments
 (0)