1
0
Fork 0
mirror of synced 2025-04-17 03:59:50 -04:00

Generate .zimrc if not found

This hopefully makes installation easier. Also, command line tools
usually create a default config file when it's missing, so this should
me a familiar behavior to command line users.
Leaving zsh-history-substring-search commented because it does not work
out of the box and unfortunately needs to be manually configured.
This commit is contained in:
Eric Nielsen 2025-03-21 07:47:12 -05:00
parent 52dd14669e
commit 987823e106
No known key found for this signature in database
GPG key ID: 678AF5E338C87D99
4 changed files with 121 additions and 1 deletions

View file

@ -3,6 +3,11 @@ _zimfw_source_zimrc() {
{
local -ri _zeager=${1}
local -i _zfailed=0
if [[ ! -e ${_zconfig} ]]; then
_zimfw_print -u2 "${_zyellow}Config file not found, will create ${_zbold}${_zconfig}${_znormal}"
command mkdir -p ${_zconfig:h} || return 1
print -R "<%= render_template("src/templates/zimrc") %>" >${_zconfig} || return 1
fi
if ! source ${_zconfig} || (( _zfailed )); then
print -u2 -R "${_zred}Failed to source ${_zbold}${_zconfig}${_znormal}"
return 1

52
src/templates/zimrc Normal file
View file

@ -0,0 +1,52 @@
#
# This is not sourced during shell startup and it's only used to configure zimfw
#
#
# Modules
#
# Sets sane Zsh built-in environment options.
zmodule environment
# Provides handy git aliases and functions.
zmodule git
# Applies correct bindkeys for input events.
zmodule input
# Sets a custom terminal title.
zmodule termtitle
# Utility aliases and functions. Adds colour to ls, grep and less.
zmodule utility
#
# Prompt
#
# Exposes to prompts how long the last command took to run, used by asciiship.
zmodule duration-info
# Exposes git repository status information to prompts, used by asciiship.
zmodule git-info
# A heavily reduced, ASCII-only version of the Spaceship and Starship prompts.
zmodule asciiship
#
# Completion
#
# Additional completion definitions for Zsh.
zmodule zsh-users/zsh-completions --fpath src
# Enables and configures smart and extensive tab completion.
# completion must be sourced after all modules that add completion definitions.
zmodule completion
#
# Modules that must be initialized last
#
# Fish-like syntax highlighting for Zsh.
# zsh-users/zsh-syntax-highlighting must be sourced after completion
zmodule zsh-users/zsh-syntax-highlighting
# Fish-like history search (up arrow) for Zsh.
# zsh-users/zsh-history-substring-search must be sourced after zsh-users/zsh-syntax-highlighting
#zmodule zsh-users/zsh-history-substring-search
# Fish-like autosuggestions for Zsh.
zmodule zsh-users/zsh-autosuggestions

View file

@ -24,6 +24,12 @@ class Zim
Dir[pattern].sort.map { |filename| render(filename) }.join("\n")
end
def render_template(filename)
render(filename)
.gsub(/\\/, "\\\\\\\\")
.gsub(/(?=\$[^']|"|`)/, "\\\\")
end
def render_commented(filename)
render(filename).gsub(/^(?=.)/, "# ").gsub(/^$/, "#")
end

View file

@ -383,6 +383,63 @@ Per-call initialization options:
{
local -ri _zeager=${1}
local -i _zfailed=0
if [[ ! -e ${_zconfig} ]]; then
_zimfw_print -u2 "${_zyellow}Config file not found, will create ${_zbold}${_zconfig}${_znormal}"
command mkdir -p ${_zconfig:h} || return 1
print -R "#
# This is not sourced during shell startup and it's only used to configure zimfw
#
#
# Modules
#
# Sets sane Zsh built-in environment options.
zmodule environment
# Provides handy git aliases and functions.
zmodule git
# Applies correct bindkeys for input events.
zmodule input
# Sets a custom terminal title.
zmodule termtitle
# Utility aliases and functions. Adds colour to ls, grep and less.
zmodule utility
#
# Prompt
#
# Exposes to prompts how long the last command took to run, used by asciiship.
zmodule duration-info
# Exposes git repository status information to prompts, used by asciiship.
zmodule git-info
# A heavily reduced, ASCII-only version of the Spaceship and Starship prompts.
zmodule asciiship
#
# Completion
#
# Additional completion definitions for Zsh.
zmodule zsh-users/zsh-completions --fpath src
# Enables and configures smart and extensive tab completion.
# completion must be sourced after all modules that add completion definitions.
zmodule completion
#
# Modules that must be initialized last
#
# Fish-like syntax highlighting for Zsh.
# zsh-users/zsh-syntax-highlighting must be sourced after completion
zmodule zsh-users/zsh-syntax-highlighting
# Fish-like history search (up arrow) for Zsh.
# zsh-users/zsh-history-substring-search must be sourced after zsh-users/zsh-syntax-highlighting
#zmodule zsh-users/zsh-history-substring-search
# Fish-like autosuggestions for Zsh.
zmodule zsh-users/zsh-autosuggestions
" >${_zconfig} || return 1
fi
if ! source ${_zconfig} || (( _zfailed )); then
print -u2 -R "${_zred}Failed to source ${_zbold}${_zconfig}${_znormal}"
return 1
@ -489,7 +546,7 @@ _zimfw_info() {
_zimfw_info_print_symlink ZIM_HOME ${ZIM_HOME}
_zimfw_info_print_symlink 'zimfw config' ${_zconfig}
_zimfw_info_print_symlink 'zimfw script' ${__ZIMFW_FILE}
print -R 'zimfw version: '${_zversion}' (built at 2025-03-20 20:43:33 UTC, previous commit is 7d0a56b)'
print -R 'zimfw version: '${_zversion}' (built at 2025-03-21 12:46:56 UTC, previous commit is 52dd146)'
local zparam
for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZSH_VERSION; do
print -R ${(r.22....:.)zparam}${(P)zparam}