Compare commits

...

12 Commits

Author SHA1 Message Date
6f1e783a56 feat(zsh): typo 2026-02-08 17:38:44 +08:00
a9080203f6 feat(zsh): delete the dependency to oh-my-zsh 2026-02-08 17:37:19 +08:00
e384a4ad0c nushell .. 2026-02-08 17:21:28 +08:00
bbc0d2f0a1 zsh helix 2026-02-04 20:03:17 +08:00
1af9a937d8 nushell completions 2026-02-02 20:33:39 +08:00
0f9b528471 nushell helix 2026-02-02 20:18:50 +08:00
0bb8f0e5e8 nushell alt-l to accept autocomplete 2026-02-02 19:36:49 +08:00
3d22ed9633 helix for zsh 2026-02-01 22:02:25 +08:00
e86f9d47e7 zsh fzf 2026-01-31 21:30:00 +08:00
21129ab5b9 zsh fzf alt-f, alt-d, alt-h 2026-01-31 20:28:24 +08:00
cacd241cca Merge branch 'main' of ssh://gitea.mmeip.cn:8022/gwbeip/TerminalPolyjuice 2026-01-30 16:48:30 +08:00
05b2a28b94 nushell config 2026-01-30 16:48:11 +08:00
20 changed files with 453 additions and 84 deletions

19
helix/config.toml Normal file
View File

@@ -0,0 +1,19 @@
theme = "onedark"
[editor]
line-number = "relative"
cursorline = true
cursorcolumn = true
default-yank-register = "+"
continue-comments = true
[editor.statusline]
left = ["mode", "spinner", "read-only-indicator", "file-modification-indicator", "version-control"]
center = ["file-name", "total-line-numbers", "position-percentage"]
right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
separator = "│"
mode.normal = "NORMAL"
mode.insert = "INSERT"
mode.select = "SELECT"
diagnostics = ["warning", "error"]
workspace-diagnostics = ["warning", "error"]

View File

@@ -1,19 +0,0 @@
alias l = ls
alias ll = ls -l
alias la = ls -a
alias lla = ls -la
alias lh = ls -lh
alias lt = ls -l | sort-by modified | reverse
alias cdi = cd (ls **/ | get name | str join "\n" | fzf)
if $env.OS == "Windows_NT" {
} else {
alias py = python3
}
alias weather = curl wttr.in
alias moon = curl wttr.in/Moon
alias quote = curl https://api.quotable.io/random | from json | get content
alias dadjoke = curl -H "Accept: application/json" https://icanhazdadjoke.com/ | from json | get joke

View File

View File

@@ -1,9 +0,0 @@
use pj_starship.nu
use pj_zoxide.nu
export def --env init [] {
# zoxide
pj_zoxide init
# starship
pj_starship init
}

View File

@@ -0,0 +1,31 @@
export alias l = ls
export alias ll = ls -l
export alias la = ls -a
export alias lla = ls -la
export alias lh = ls -lh
export alias lt = ls -l | sort-by modified | reverse
export alias .. = cd ..
export alias ... = cd ../..
export alias .... = cd ../../..
export alias ..... = cd ../../../..
export alias ...... = cd ../../../../..
export alias ....... = cd ../../../../../..
export alias ........ = cd ../../../../../../..
export alias .......... = cd ../../../../../../../..
export def py [...rest: string] {
if (which ^py | is-not-empty) {
^py ...$rest
} else if (which ^python3 | is-not-empty) {
^python3 ...$rest
} else {
print "Error: Python is not installed or could not be found."
}
}
export alias weather = curl wttr.in
export alias moon = curl wttr.in/Moon
export alias quote = curl https://api.quotable.io/random | from json | get content
export alias dadjoke = curl -H "Accept: application/json" https://icanhazdadjoke.com/ | from json | get joke

View File

@@ -0,0 +1,14 @@
export-env {
$env.config = {
completions: {
quick: true
partial: true
algorithm: "fuzzy"
case_sensitive: false
external: {
enable: true
max_results: 100
}
}
}
}

85
nushell/modules/pj_fzf.nu Normal file
View File

@@ -0,0 +1,85 @@
# History
const fzf_history_selector = {
name: fzf_history_selector
modifier: alt
keycode: char_h
mode: [emacs, vi_insert, vi_normal]
event: [
{
send: executehostcommand
cmd: "
let result = history
| reverse
| get command
| str replace --all (char newline) ' '
| to text
| fzf --height 40% --reverse --border;
commandline edit --append $result;
commandline set-cursor --end
"
}
]
}
const fzf_file_selector = {
name: fzf_file_selector
modifier: alt
keycode: char_f
mode: [emacs, vi_insert, vi_normal]
event: [
{
send: executehostcommand
cmd: "
let result = (ls **/* | where type == 'file' | get name | to text | fzf --height 40% --reverse --border);
commandline edit --append $result;
commandline set-cursor --end
"
}
]
}
const fzf_dir_selector = {
name: fzf_dir_selector
modifier: alt
keycode: char_d
mode: [emacs, vi_insert, vi_normal]
event: [
{
send: executehostcommand
cmd: "
let result = (ls **/ | where type == 'dir' | get name | to text | fzf --height 40% --reverse --border);
commandline edit --append $result;
commandline set-cursor --end
"
}
]
}
# Update the $env.config
export-env {
# Only append if not already present (check by name)
let has_history_menu = $env.config.keybindings | any {|kb| $kb.name == "fzf_history_selector"}
if not $has_history_menu {
$env.config.keybindings = $env.config.keybindings | append [
$fzf_history_selector
]
}
# Only append if not already present (check by name)
let has_fzf_file_selector = $env.config.keybindings | any {|kb| $kb.name == "fzf_file_selector"}
if not $has_fzf_file_selector {
$env.config.keybindings = $env.config.keybindings | append [
$fzf_file_selector
]
}
# Only append if not already present (check by name)
let has_fzf_dir_selector = $env.config.keybindings | any {|kb| $kb.name == "fzf_dir_selector"}
if not $has_fzf_dir_selector {
$env.config.keybindings = $env.config.keybindings | append [
$fzf_dir_selector
]
}
}
export alias cdi = cd (ls **/ | get name | str join "\n" | fzf)

View File

@@ -0,0 +1,33 @@
export-env {
$env.PJ_HELIX_CONFIG_PATH = $env.NU_POLYJUICE_PATH | path join ".." "helix" "config.toml"
}
export def hx [...rest: string] {
if (which ^helix | is-not-empty) {
^helix -c $env.PJ_HELIX_CONFIG_PATH ...$rest
} else if (which ^hx | is-not-empty) {
^hx -c $env.PJ_HELIX_CONFIG_PATH ...$rest
} else {
print "Helix editor not found."
if ($env.OS == "Windows_NT") {
print "You can install Helix via `winget install Helix.Helix`"
} else {
print "You can install Helix from package managers."
}
}
}
export def helix [...rest: string] {
if (which ^helix | is-not-empty) {
^helix -c $env.PJ_HELIX_CONFIG_PATH ...$rest
} else if (which ^hx | is-not-empty) {
^hx -c $env.PJ_HELIX_CONFIG_PATH ...$rest
} else {
print "Helix editor not found."
if ($env.OS == "Windows_NT") {
print "You can install Helix via `winget install Helix.Helix`"
} else {
print "You can install Helix from package managers."
}
}
}

View File

@@ -0,0 +1,42 @@
const alt_l_history_completion = {
name: alt_l_history_completion
modifier: alt
keycode: char_l
mode: [emacs, vi_insert, vi_normal]
event: {
until: [
{ send: historyhintcomplete }
{ send: menuright }
{ send: right }
]
}
}
const alt_uppercasel_history_completion = {
name: alt_uppercasel_history_completion
modifier: alt_shift
keycode: char_l
mode: [emacs, vi_insert, vi_normal]
event: {
until: [
{ send: historyhintwordcomplete }
{ edit: movewordright, select: false}
]
}
}
export-env {
let has_alt_l_history_completion = $env.config.keybindings | where name == "alt_l_history_completion" | is-not-empty
if not $has_alt_l_history_completion {
$env.config.keybindings = $env.config.keybindings | append [
$alt_l_history_completion
]
}
let has_alt_uppercasel_history_completion = $env.config.keybindings | where name == "alt_uppercasel_history_completion" | is-not-empty
if not $has_alt_uppercasel_history_completion {
$env.config.keybindings = $env.config.keybindings | append [
$alt_uppercasel_history_completion
]
}
}

View File

@@ -0,0 +1,56 @@
export def --env "pj starship config" [name: string] {
if (which ^starship | is-empty) {
echo "starship is not installed."
return
}
$env.starship_config = ($env.NU_POLYJUICE_PATH | path join ".." "starship" $"starship_($name).toml")
}
export def --env "pj starship list" [] {
if (which ^starship | is-empty) {
echo "starship is not installed."
return
}
ls ($env.NU_POLYJUICE_PATH | path join ".." "starship") -s | get name | parse -r '^(starship_(?<name>.*).toml)$' | get name
}
export-env {
if (which ^starship | is-not-empty) {
$env.STARSHIP_SHELL = "nu"
load-env {
STARSHIP_SESSION_KEY: (random chars -l 16)
PROMPT_MULTILINE_INDICATOR: (
^'starship' prompt --continuation
)
# Does not play well with default character module.
# TODO: Also Use starship vi mode indicators?
PROMPT_INDICATOR: ""
PROMPT_COMMAND: {||
# jobs are not supported
(
^'starship' prompt
--cmd-duration $env.CMD_DURATION_MS
$"--status=($env.LAST_EXIT_CODE)"
--terminal-width (term size).columns
)
}
config: ($env.config? | default {} | merge {
render_right_prompt_on_last_line: true
})
PROMPT_COMMAND_RIGHT: {||
(
^'starship' prompt
--right
--cmd-duration $env.CMD_DURATION_MS
$"--status=($env.LAST_EXIT_CODE)"
--terminal-width (term size).columns
)
}
}
$env.starship_config = ($env.NU_POLYJUICE_PATH | path join ".." "starship" $"starship_default.toml")
}
}

View File

@@ -1,11 +0,0 @@
export def --env config [name: string] {
$env.starship_config = ($env.NU_POLYJUICE_PATH | path join ".." "starship" $"starship_($name).toml")
}
export def --env init [] {
let starship_nushell_path = ($env.NU_POLYJUICE_AUTOLOAD_DIRS | path join "starship.nu")
if ($starship_nushell_path | path exists) {
rm $starship_nushell_path
}
starship init nu | save -f $starship_nushell_path
}

View File

@@ -1,7 +1,81 @@
export def --env init [] {
let zoxide_nushell_path = ($env.NU_POLYJUICE_AUTOLOAD_DIRS | path join "zoxide.nu")
if ($zoxide_nushell_path | path exists) {
rm $zoxide_nushell_path
}
zoxide init nushell --cmd z | save -f $zoxide_nushell_path
# export def --env init [] {
# let zoxide_nushell_path = ($env.NU_POLYJUICE_AUTOLOAD_DIRS | path join "zoxide.nu")
# if ($zoxide_nushell_path | path exists) {
# rm $zoxide_nushell_path
# }
# zoxide init nushell --cmd z | save -f $zoxide_nushell_path
# }
# Code generated by zoxide. DO NOT EDIT.
# =============================================================================
#
# Hook configuration for zoxide.
#
# Initialize hook to add new entries to the database.
export-env {
$env.config = (
$env.config?
| default {}
| upsert hooks { default {} }
| upsert hooks.env_change { default {} }
| upsert hooks.env_change.PWD { default [] }
)
let __zoxide_hooked = (
$env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { false } }
)
if not $__zoxide_hooked {
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append {
__zoxide_hook: true,
code: {|_, dir| zoxide add -- $dir}
})
}
}
# =============================================================================
#
# When using zoxide with --no-cmd, alias these internal functions as desired.
#
# Jump to a directory using only keywords.
def --env --wrapped __zoxide_z [...rest: string] {
let path = match $rest {
[] => {'~'},
[ '-' ] => {'-'},
[ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg}
_ => {
zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
}
}
cd $path
}
# Jump to a directory using interactive search.
def --env --wrapped __zoxide_zi [...rest:string] {
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
}
# =============================================================================
#
# Commands for zoxide. Disable these using --no-cmd.
#
export alias z = __zoxide_z
export alias zi = __zoxide_zi
# =============================================================================
#
# Add this to your env file (find it by running `$nu.env-path` in Nushell):
#
# zoxide init nushell | save -f ~/.zoxide.nu
#
# Now, add this to the end of your config file (find it by running
# `$nu.config-path` in Nushell):
#
# source ~/.zoxide.nu
#
# Note: zoxide only supports Nushell v0.89.0+.

View File

@@ -3,15 +3,12 @@ $env.config.show_banner = false
# Terminal Polyjuice Files's Path
$env.NU_POLYJUICE_PATH = $env.FILE_PWD
$env.NU_POLYJUICE_CACHE_PATH = $env.NU_POLYJUICE_PATH + "/cache"
$env.NU_POLYJUICE_AUTOLOAD_DIRS = ($nu.user-autoload-dirs)
# modules
use modules/pj.nu
use modules/pj_starship.nu
use modules/pj_zoxide.nu
source aliases/pj_aliases.nu
# starship
pj_starship config "default"
use modules/pj_aliases.nu *
use modules/pj_completions.nu *
use modules/pj_helix.nu *
use modules/pj_fzf.nu *
use modules/pj_zoxide.nu *
use modules/pj_historyhintcomplete.nu *
use modules/pj_prompt.nu *

View File

@@ -53,7 +53,7 @@ alias -g P="2>&1| pygmentize -l pytb"
alias dud='du -d 1 -h'
(( $+commands[duf] )) || alias duf='du -sh *'
(( $+commands[fd] )) || alias fd='find . -type d -name'
# (( $+commands[fd] )) || alias fd='find . -type d -name'
alias ff='find . -type f -name'
alias h='history'

View File

@@ -1,11 +1,56 @@
eval "$(fzf --zsh)"
if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then
if (( $+commands[fd] )); then
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
elif (( $+commands[rg] )); then
export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git/*"'
elif (( $+commands[ag] )); then
export FZF_DEFAULT_COMMAND='ag -l --hidden -g "" --ignore .git'
fi
if (( $+commands[fd] )); then
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
elif (( $+commands[rg] )); then
export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git/*"'
elif (( $+commands[ag] )); then
export FZF_DEFAULT_COMMAND='ag -l --hidden -g "" --ignore .git'
fi
fi
# alt-f to search files with fzf
function fzf-file-widget() {
local selected_file
local command_to_run="fzf"
if (( $+commands[fd] )); then
command_to_run="fd --type f --hidden --exclude .git | fzf"
elif (( $+commands[rg] )); then
command_to_run='rg --files --hidden --glob "!.git/*" | fzf'
elif (( $+commands[ag] )); then
command_to_run='ag -l --hidden -g "" --ignore .git | fzf'
else
command_to_run='find . -type f | fzf'
fi
selected_file=$(eval $command_to_run)
LBUFFER+="$selected_file"
}
# alt-f to trigger file search
zle -N fzf-file-widget
bindkey '\ef' fzf-file-widget
# alt-d to search directories with fzf
function fzf-directory-widget() {
local selected_dir
local command_to_run
if (( $+commands[fd] )); then
command_to_run="fd --type d --hidden --no-ignore --exclude .git | fzf"
else
command_to_run='find . -type d | fzf'
fi
selected_dir=$(eval $command_to_run)
LBUFFER+="$selected_dir"
}
# alt-d to trigger directory search
zle -N fzf-directory-widget
bindkey '\ed' fzf-directory-widget
# alt-h to search command history with fzf
function fzf-history-widget() {
local selected_command
selected_command=$(fc -frl 1 | fzf | awk '{$1=$2=$3=""; gsub(/^ +/, ""); print}')
LBUFFER+="$selected_command"
}
# alt-h to trigger history search
zle -N fzf-history-widget
bindkey '\eh' fzf-history-widget

10
zsh/alias/helix_alias.sh Normal file
View File

@@ -0,0 +1,10 @@
if (( $+commands[helix] )); then
alias helix="helix -c $ZSH_POLYJUICE_HELIX_CONFIG_FILE"
alias hx="helix -c $ZSH_POLYJUICE_HELIX_CONFIG_FILE"
elif (( $+commands[hx] )); then
alias helix="hx -c $ZSH_POLYJUICE_HELIX_CONFIG_FILE"
alias hx="hx -c $ZSH_POLYJUICE_HELIX_CONFIG_FILE"
else
alias helix="echo HELIX is not installed"
alias hx="echo HELIX/HX is not installed"
fi

View File

@@ -22,9 +22,9 @@ function pj_check() {
fi
# check for oh-my-zsh
if [[ ! -d $ZSH_POLYJUICE_PLUGINS_PATH/ohmyzsh ]]; then
echo "oh-my-zsh is not installed."
fi
# if [[ ! -d $ZSH_POLYJUICE_PLUGINS_PATH/ohmyzsh ]]; then
# echo "oh-my-zsh is not installed."
# fi
# check for zoxide
if (( ! $+commands[zoxide] )); then

View File

@@ -73,20 +73,20 @@ function pj_install_plugins() {
fi
# git clone oh-my-zsh
if [ ! -d "$ZSH_POLYJUICE_PLUGINS_PATH"/ohmyzsh ]; then
echo "Oh My Zsh is not downloaded. Downloading..."
# git clone https://github.com/ohmyzsh/ohmyzsh.git "$PATH_OHMYZSH"
git clone https://gitee.com/mirrors/ohmyzsh.git "$ZSH_POLYJUICE_PLUGINS_PATH"/ohmyzsh
else
cd "$ZSH_POLYJUICE_PLUGINS_PATH"/ohmyzsh
if [ ! -d .git ]; then
echo "Oh My Zsh is not a git repository. Please remove $ZSH_POLYJUICE_PLUGINS_PATH/ohmyzsh and try again."
else
echo "Oh My Zsh is already exist. Updating..."
git pull
fi
cd -
fi
# if [ ! -d "$ZSH_POLYJUICE_PLUGINS_PATH"/ohmyzsh ]; then
# echo "Oh My Zsh is not downloaded. Downloading..."
# # git clone https://github.com/ohmyzsh/ohmyzsh.git "$PATH_OHMYZSH"
# git clone https://gitee.com/mirrors/ohmyzsh.git "$ZSH_POLYJUICE_PLUGINS_PATH"/ohmyzsh
# else
# cd "$ZSH_POLYJUICE_PLUGINS_PATH"/ohmyzsh
# if [ ! -d .git ]; then
# echo "Oh My Zsh is not a git repository. Please remove $ZSH_POLYJUICE_PLUGINS_PATH/ohmyzsh and try again."
# else
# echo "Oh My Zsh is already exist. Updating..."
# git pull
# fi
# cd -
# fi
echo "All plugins are installed/updated. Run 'exec zsh' to apply changes."
}

View File

@@ -1,6 +1,7 @@
# "[interop] appendWindowsPath=false" in /etc/wsl.conf is setted
# Append VSCode on Windows into PATH so that vscode can be used in WSL
export PATH=$PATH:'/mnt/c/Users/gwbei/AppData/Local/Programs/Microsoft VS Code/bin/'
export PATH=$PATH:'/mnt/c/Users/gwbei/AppData/Local/Programs/Zed/bin/zed'
# Language and encoding related
export LC_ALL=C.UTF-8
export LC_ALL=C.UTF-8

View File

@@ -21,6 +21,7 @@ export ZSH_POLYJUICE_ALIAS_PATH="$ZSH_POLYJUICE_PATH/alias"
export ZSH_POLYJUICE_SETTINGS_PATH="$ZSH_POLYJUICE_PATH/settings"
export ZSH_POLYJUICE_FUNCTIONS_PATH="$ZSH_POLYJUICE_PATH/functions"
export ZSH_POLYJUICE_STARSHIP_CONFIG_FILE="$ZSH_POLYJUICE_PATH/../starship/starship_default.toml"
export ZSH_POLYJUICE_HELIX_CONFIG_FILE="$ZSH_POLYJUICE_PATH/../helix/config.toml"
# Load basic settings `zsh/settings`
for _file in "$ZSH_POLYJUICE_SETTINGS_PATH"/*.sh; do
@@ -54,7 +55,7 @@ if [[ -f $ZSH_POLYJUICE_PLUGINS_PATH/zsh-syntax-highlighting/zsh-syntax-highligh
source $ZSH_POLYJUICE_PLUGINS_PATH/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh
fi
if [[ -f $ZSH_POLYJUICE_PLUGINS_PATH/fzf-tab/fzf-tab.plugin.zsh ]]; then
source $ZSH_POLYJUICE_PLUGINS_PATH/fzf-tab/fzf-tab.plugin.zsh # relies on fzf itself and zsh-autosuggestions plugin
source $ZSH_POLYJUICE_PLUGINS_PATH/fzf-tab/fzf-tab.plugin.zsh # relies on fzf itself and zsh-autocomplete plugin
fi
# using starship as prompt