mkhomedir
mksourcedir

# test that chezmoi edit edits a single file
chezmoi edit $HOME${/}.file
grep -count=1 '# edited' $CHEZMOISOURCEDIR/dot_file
! grep '# edited' $HOME/.file

# test that chezmoi edit --apply applies the edit.
chezmoi edit --apply --force $HOME${/}.file
grep -count=2 '# edited' $CHEZMOISOURCEDIR/dot_file
grep -count=2 '# edited' $HOME/.file

# test that chezmoi edit edits a symlink
chezmoi edit $HOME${/}.symlink
grep -count=1 '# edited' $CHEZMOISOURCEDIR/symlink_dot_symlink

# test that chezmoi edit edits a script
chezmoi edit $HOME${/}script
grep -count=1 '# edited' $CHEZMOISOURCEDIR/run_script

# test that chezmoi edit edits a file and a symlink
chezmoi edit $HOME${/}.file $HOME${/}.symlink
grep -count=3 '# edited' $CHEZMOISOURCEDIR/dot_file
grep -count=2 '# edited' $CHEZMOISOURCEDIR/symlink_dot_symlink

# test that chezmoi edit edits the working tree
chezmoi edit
exists $CHEZMOISOURCEDIR/.edited

# test that chezmoi edit edits a directory
[!windows] chezmoi edit $HOME${/}.dir
[!windows] exists $CHEZMOISOURCEDIR/dot_dir/.edited

chhome home2/user

# test that chezmoi edit edits a file when the working tree and the source dir are different
chezmoi edit $HOME${/}.file
grep -count=1 '# edited' $CHEZMOISOURCEDIR/home/dot_file

# test that chezmoi edit edits the working tree when working tree and the source dir are different
chezmoi edit
exists $CHEZMOISOURCEDIR/.edited
! exists $CHEZMOISOURCEDIR/home/.edited

-- home/user/.local/share/chezmoi/run_script --
#!/bin/sh
-- home2/user/.config/chezmoi/chezmoi.toml --
sourceDir = "~/.local/share/chezmoi/home"
-- home2/user/.local/share/chezmoi/.git/.keep --
-- home2/user/.local/share/chezmoi/home/dot_file --
# contents of .file
