mirror of
https://github.com/zoriya/flake.git
synced 2025-12-06 06:36:19 +00:00
Hand write a prompt
This commit is contained in:
@@ -4,10 +4,6 @@
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
imports = [
|
||||
./starship.nix
|
||||
];
|
||||
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
autocd = true;
|
||||
@@ -216,6 +212,8 @@
|
||||
# disable space between right prompt and end of line
|
||||
ZLE_RPROMPT_INDENT=0
|
||||
'')
|
||||
(lib.mkOrder 950 "source ${pkgs.gitstatus}/share/gitstatus/gitstatus.prompt.zsh")
|
||||
(lib.mkOrder 951 (builtins.readFile ./prompt.zsh))
|
||||
(lib.mkOrder 1000 (builtins.readFile ./init.zsh))
|
||||
(lib.mkOrder 1400 ''
|
||||
# only start atuin if it's in the path (fix distrobox or other temp fs issues)
|
||||
@@ -224,9 +222,6 @@
|
||||
fi
|
||||
'')
|
||||
(lib.mkOrder 1410 "${lib.getExe pkgs.nix-your-shell} zsh | source /dev/stdin")
|
||||
(lib.mkOrder 1420 ''
|
||||
${lib.getExe pkgs.starship} init zsh | source /dev/stdin
|
||||
'')
|
||||
];
|
||||
|
||||
envExtra = ''
|
||||
|
||||
@@ -1,48 +1,56 @@
|
||||
setopt promptsubst
|
||||
zmodload zsh/datetime
|
||||
zmodload zsh/mathfunc
|
||||
|
||||
# (){
|
||||
# local left right invisible leftcontent
|
||||
#
|
||||
# # User name.
|
||||
# left+='%B%F{black}%K{green} %n '
|
||||
# # Current working directory.
|
||||
# left+='%K{yellow} %~ '
|
||||
#
|
||||
# # Version control branch.
|
||||
# right='${vcs_info_msg_0_:+${vcs_info_msg_0_//[%]/%%} }'
|
||||
# # Virtualenv.
|
||||
# export VIRTUAL_ENV_DISABLE_PROMP=1
|
||||
# right+='${VIRTUAL_ENV:+venv }'
|
||||
#
|
||||
# # Editing mode. $ZLE_MODE shouldn't contain %, no need to escape
|
||||
# ZLE_MODE=insert
|
||||
# right+='%K{green} $ZLE_MODE'
|
||||
#
|
||||
# # closing
|
||||
# right+=$' %k%f%b'
|
||||
#
|
||||
# # Combine left and right prompt with spacing in between.
|
||||
# invisible='%([BSUbfksu]|([FBK]|){*})'
|
||||
#
|
||||
# leftcontent=${(S)left//$~invisible}
|
||||
# rightcontent=${(S)right//$~invisible}
|
||||
#
|
||||
# PS1="$left\${(l,COLUMNS-\${#\${(%):-$leftcontent$rightcontent}},)}$right%{"$'\n%}$ '
|
||||
# }
|
||||
timer_preexec() {
|
||||
timer=$EPOCHREALTIME
|
||||
}
|
||||
add-zsh-hook preexec timer_precmd
|
||||
timer_precmd() {
|
||||
if [ -z $timer ]; then
|
||||
EXEC_TIME=""
|
||||
return
|
||||
fi
|
||||
local d_s=$((EPOCHREALTIME - timer))
|
||||
local s=$((int(rint(d_s % 60))))
|
||||
local m=$((int(rint( (d_s / 60) % 60 ))))
|
||||
local h=$((int(rint(d_s / 3600))))
|
||||
|
||||
if ((h > 0)); then EXEC_TIME=${h}h${m}m
|
||||
elif ((m > 0)); then EXEC_TIME=${m}m${s}s
|
||||
elif ((s > 0)); then EXEC_TIME=${s}s
|
||||
else unset EXEC_TIME
|
||||
fi
|
||||
unset timer
|
||||
}
|
||||
add-zsh-hook precmd timer_precmd
|
||||
|
||||
|
||||
kube_check_time=0
|
||||
kube_precmd() {
|
||||
local mtime=$(zstat +mtime ${KUBECONFIG-~/.kube/config})
|
||||
if [[ $mtime -gt $kube_check_time ]]; then
|
||||
KCTX=$(kubectl config current-context)
|
||||
KNS=$(kubectl config view --minify --output 'jsonpath={..namespace}')
|
||||
kube_check_time=$EPOCHREALTIME
|
||||
fi
|
||||
}
|
||||
add-zsh-hook precmd kube_precmd
|
||||
|
||||
|
||||
FILL="%F{#808080}${(l.$COLUMNS..·.)}%f"
|
||||
NEWLINE=$'\n'
|
||||
|
||||
WORKDIR='%B%F{blue}%~%b%f'
|
||||
|
||||
autoload -Uz vcs_info
|
||||
zstyle ':vcs_info:*' enable git
|
||||
zstyle ':vcs_info:git*' formats '(%b)'
|
||||
precmd() {
|
||||
vcs_info
|
||||
}
|
||||
GIT='%F{green}$vcs_info_msg_0_%f'
|
||||
|
||||
RO='%F{red}$([ -w . ] || echo ':ro")%f"
|
||||
# from gitstatusd, sourced before this prompt script
|
||||
GIT='($GITSTATUS_PROMPT)'
|
||||
KUBE='%F{cyan}$KCTX/$KNS%f'
|
||||
PROMPT_SHLVL='%(?.%F{green}.%F{red})$(printf "❯%.0s" {1..$SHLVL})%f'
|
||||
|
||||
# %(?.%F{green}>.$F{red}>.)
|
||||
EXEC_TIME=""
|
||||
EXIT_CODE=' %(?..%F{red}x${(j[|])pipestatus}%f)'
|
||||
JOBS=' %F{cyan}%(1j.&%j.)%f'
|
||||
|
||||
export PROMPT="-----\n$WORKDIR $GIT $PROMPT_SHLVL "
|
||||
export RPROMPT='%j'
|
||||
export PROMPT="${FILL}${NEWLINE}$WORKDIR$RO $GIT $KUBE $PROMPT_SHLVL "
|
||||
export RPROMPT="\${EXEC_TIME}${EXIT_CODE}${JOBS}"
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
{lib, ...}: {
|
||||
programs.starship = {
|
||||
enable = true;
|
||||
# integrate manually
|
||||
enableZshIntegration = false;
|
||||
settings = {
|
||||
add_newline = false;
|
||||
|
||||
format = lib.concatStrings [
|
||||
"$fill"
|
||||
"$hostname"
|
||||
"$python"
|
||||
"$nix_shell"
|
||||
"$container"
|
||||
"$line_break"
|
||||
"$directory"
|
||||
"[(\\($git_branch$git_commit$git_status$git_state\\) )](green)"
|
||||
"$kubernetes"
|
||||
"$shlvl"
|
||||
"$character"
|
||||
];
|
||||
|
||||
right_format = lib.concatStrings [
|
||||
"$cmd_duration"
|
||||
"$status"
|
||||
"$jobs"
|
||||
];
|
||||
|
||||
fill = {
|
||||
symbol = "·";
|
||||
style = "fg:#808080";
|
||||
};
|
||||
|
||||
directory = {
|
||||
truncate_to_repo = false;
|
||||
fish_style_pwd_dir_length = 1;
|
||||
read_only = ":ro";
|
||||
style = "bold fg:#00AFFF";
|
||||
};
|
||||
|
||||
git_branch = {
|
||||
format = "([($branch(: $remote_branch))]($style))";
|
||||
only_attached = true;
|
||||
style = "green";
|
||||
};
|
||||
|
||||
git_commit = {
|
||||
format = "[($hash$tag)]($style)";
|
||||
style = "green";
|
||||
only_detached = true;
|
||||
tag_disabled = false;
|
||||
tag_symbol = " ";
|
||||
};
|
||||
|
||||
git_status = {
|
||||
format = "([$all_status$ahead_behind]($style))";
|
||||
style = "yellow";
|
||||
ahead = " ⇡$count";
|
||||
behind = " ⇣$count";
|
||||
diverged = "";
|
||||
conflicted = " =$count";
|
||||
untracked = " ?$count";
|
||||
stashed = " *$count";
|
||||
modified = " !$count";
|
||||
staged = " +$count";
|
||||
deleted = "";
|
||||
renamed = "";
|
||||
};
|
||||
|
||||
git_state = {
|
||||
format = "( [$state( $progress_current/$progress_total)]($style))";
|
||||
};
|
||||
|
||||
status = {
|
||||
format = " [($symbol$status(-$signal_name))]($style)";
|
||||
pipestatus_format = "[$symbol$pipestatus]($style)";
|
||||
pipestatus_segment_format = "[($signal_name )$status]($style)";
|
||||
symbol = "x";
|
||||
pipestatus = true;
|
||||
disabled = false;
|
||||
};
|
||||
|
||||
kubernetes = {
|
||||
format = "[$context(/$namespace) ]($style)";
|
||||
disabled = false;
|
||||
};
|
||||
|
||||
cmd_duration = {
|
||||
format = " [$duration]($style)";
|
||||
};
|
||||
|
||||
jobs = {
|
||||
symbol = "&";
|
||||
format = " [$symbol$number]($style)";
|
||||
};
|
||||
|
||||
python = {
|
||||
format = "[( \($virtualenv\))]($style)";
|
||||
};
|
||||
|
||||
nix_shell = {
|
||||
format = "[\( $name\) nix]($style)";
|
||||
style = "cyan";
|
||||
heuristic = true;
|
||||
};
|
||||
|
||||
container = {
|
||||
format = "[ $name]($style)";
|
||||
};
|
||||
|
||||
hostname = {
|
||||
format = "[ $ssh_symbol$hostname]($style)";
|
||||
};
|
||||
|
||||
shlvl = {
|
||||
disabled = false;
|
||||
format = "[$symbol]($style)";
|
||||
repeat = true;
|
||||
symbol = "❯";
|
||||
repeat_offset = 1;
|
||||
threshold = 0;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -128,7 +128,7 @@ in
|
||||
haskell-language-server
|
||||
rust-analyzer
|
||||
clang-tools
|
||||
roslyn-ls
|
||||
# roslyn-ls
|
||||
basedpyright
|
||||
typescript-language-server
|
||||
nil
|
||||
|
||||
Reference in New Issue
Block a user