Switch to snake case

This commit is contained in:
Ilan Cosman 2021-05-12 13:13:51 -07:00
parent 8ebdffab21
commit 67def5c37b
12 changed files with 112 additions and 114 deletions

View File

@ -25,11 +25,8 @@ If you have any questions that aren't addressed in this document, please don't h
### Naming Conventions
Local variables should be named in `camelCase`.
- `set -l numberOfNewlines`
Anything exposed to the shell or user--functions, global/universal variables, and files--should be named in `snake_case`, beginning with `tide_`. Prepend an underscore if the user in not meant to interact directly with it.
Everything (variables, files, functions) should be named in `snake_case`, beginning with `tide_`.
Prepend an underscore if the user in not meant to interact directly with it.
- `set -g _tide_left_prompt_height`
- `set -U tide_right_prompt_items`

View File

@ -16,11 +16,11 @@ end
function _tide_detect_os_linux_cases -a file key
test -e $file || return
set -l splitFile (string split '=' <$file)
set -l keyIndex (contains --index $key $splitFile) || return
set -l value (string trim --chars='"' $splitFile[(math $keyIndex + 1)] | string lower)
set -l split_file (string split '=' <$file)
set -l key_index (contains --index $key $split_file) || return
set -l value (string trim --chars='"' $split_file[(math $key_index + 1)] | string lower)
set -l distroIcons \
set -l distro_icons \
alpine  \
aosc  \
arch  \
@ -42,6 +42,6 @@ function _tide_detect_os_linux_cases -a file key
tumbleweed  \
ubuntu
set -l distroIndex (contains --index $value $distroIcons) || return
printf '%s' $distroIcons[(math $distroIndex + 1)]
set -l distro_index (contains --index $value $distro_icons) || return
printf '%s' $distro_icons[(math $distro_index + 1)]
end

View File

@ -2,73 +2,73 @@ function _tide_item_git
set -l location (git branch --show-current 2>/dev/null) || return
# --quiet=don't complain if there are no commits
git rev-parse --quiet --git-dir --is-inside-git-dir --short HEAD |
read --local --line gitDir isInsideGitDir sha
read --local --line git_dir is_inside_git_dir sha
# Default to branch, then tag, then sha
if test -z "$location" # Default to branch
set location (git tag --points-at HEAD)[1] # only get the first tag
set locationCharacter '#'
set location_character '#'
if test -z "$location"
set location $sha
set locationCharacter '@'
set location_character '@'
end
end
# Operation
set -l operation
set -l step
set -l totalSteps
set -l total_steps
if test -d $gitDir/rebase-merge
read step <$gitDir/rebase-merge/msgnum
read totalSteps <$gitDir/rebase-merge/end
if test -f $gitDir/rebase-merge/interactive
if test -d $git_dir/rebase-merge
read step <$git_dir/rebase-merge/msgnum
read total_steps <$git_dir/rebase-merge/end
if test -f $git_dir/rebase-merge/interactive
set operation rebase-i
else
set operation rebase-m
end
else if test -d $gitDir/rebase-apply
read step <$gitDir/rebase-apply/next
read totalSteps <$gitDir/rebase-apply/last
if test -f $gitDir/rebase-apply/rebasing
else if test -d $git_dir/rebase-apply
read step <$git_dir/rebase-apply/next
read total_steps <$git_dir/rebase-apply/last
if test -f $git_dir/rebase-apply/rebasing
set operation rebase
else if test -f $gitDir/rebase-apply/applying
else if test -f $git_dir/rebase-apply/applying
set operation am
else
set operation am/rebase
end
else if test -f $gitDir/MERGE_HEAD
else if test -f $git_dir/MERGE_HEAD
set operation merge
else if test -f $gitDir/CHERRY_PICK_HEAD
else if test -f $git_dir/CHERRY_PICK_HEAD
set operation cherry-pick
else if test -f $gitDir/REVERT_HEAD
else if test -f $git_dir/REVERT_HEAD
set operation revert
else if test -f $gitDir/BISECT_LOG
else if test -f $git_dir/BISECT_LOG
set operation bisect
end
# Upstream behind/ahead
# Suppress errors in case there is no upstream
git rev-list --count --left-right @{upstream}...HEAD 2>/dev/null |
read --local --delimiter=\t upstreamBehind upstreamAhead
test "$upstreamBehind" = 0 && set -e upstreamBehind
test "$upstreamAhead" = 0 && set -e upstreamAhead
read --local --delimiter=\t upstream_behind upstream_ahead
test "$upstream_behind" = 0 && set -e upstream_behind
test "$upstream_ahead" = 0 && set -e upstream_ahead
# Git status/stash
test "$isInsideGitDir" = true && set -l gitSetDirOption -C $gitDir/..
test "$is_inside_git_dir" = true && set -l git_set_dir_option -C $git_dir/..
# Suppress errors in case we are in a bare repo
set -l gitInfo (git $gitSetDirOption --no-optional-locks status --porcelain 2>/dev/null)
set -l stash (git $gitSetDirOption stash list 2>/dev/null | count) || set -e stash
set -l conflicted (string match --regex '^UU' $gitInfo | count) || set -e conflicted
set -l staged (string match --regex '^[ADMR].' $gitInfo | count) || set -e staged
set -l dirty (string match --regex '^.[ADMR]' $gitInfo | count) || set -e dirty
set -l untracked (string match --regex '^\?\?' $gitInfo | count) || set -e untracked
set -l git_info (git $git_set_dir_option --no-optional-locks status --porcelain 2>/dev/null)
set -l stash (git $git_set_dir_option stash list 2>/dev/null | count) || set -e stash
set -l conflicted (string match --regex '^UU' $git_info | count) || set -e conflicted
set -l staged (string match --regex '^[ADMR].' $git_info | count) || set -e staged
set -l dirty (string match --regex '^.[ADMR]' $git_info | count) || set -e dirty
set -l untracked (string match --regex '^\?\?' $git_info | count) || set -e untracked
# Print the information
_tide_print_item git \
$locationCharacter (set_color $tide_git_branch_color) $location \
(set_color $tide_git_operation_color) ' '$operation ' '$step/$totalSteps \
(set_color $tide_git_upstream_color) ' ⇣'$upstreamBehind ' ⇡'$upstreamAhead \
$location_character (set_color $tide_git_branch_color) $location \
(set_color $tide_git_operation_color) ' '$operation ' '$step/$total_steps \
(set_color $tide_git_upstream_color) ' ⇣'$upstream_behind ' ⇡'$upstream_ahead \
(set_color $tide_git_stash_color) ' *'$stash \
(set_color $tide_git_conflicted_color) ' ~'$conflicted \
(set_color $tide_git_staged_color) ' +'$staged \

View File

@ -1,5 +1,5 @@
function _tide_item_newline
set_color $_tide_previous_bg_color -b normal
sideWorkingOnSuffixName=tide_"$_tide_which_side_working_on"_prompt_suffix printf '%s' $$sideWorkingOnSuffixName \n
side_working_on_suffix_name=tide_"$_tide_which_side_working_on"_prompt_suffix printf '%s' $$side_working_on_suffix_name \n
set -g _tide_last_item newline
end

View File

@ -1,4 +1,4 @@
function _tide_item_nvm
set -l nvmCurrent (nvm current)
test "$nvmCurrent" != system && _tide_print_item nvm $tide_nvm_icon' ' $nvmCurrent
set -l nvm_current (nvm current)
test "$nvm_current" != system && _tide_print_item nvm $tide_nvm_icon' ' $nvm_current
end

View File

@ -1,43 +1,43 @@
function _tide_item_pwd
set -l colorDirs (set_color $tide_pwd_color_dirs || echo)
set -l colorAnchors (set_color -o $tide_pwd_color_anchors || echo)
set -l keepBackgroundColor (set_color normal -b $tide_pwd_bg_color || echo)
set -l colorTruncatedDirs (set_color $tide_pwd_color_truncated_dirs || echo)
set -l color_dirs (set_color $tide_pwd_color_dirs || echo)
set -l color_anchors (set_color -o $tide_pwd_color_anchors || echo)
set -l keep_background_color (set_color normal -b $tide_pwd_bg_color || echo)
set -l color_truncated_dirs (set_color $tide_pwd_color_truncated_dirs || echo)
set -l splitPwd (string replace -- $HOME '~' $PWD | string split --no-empty '/')
set -l splitPwdForLength $splitPwd
set -l splitPwdForOutput $splitPwd
set -l split_pwd (string replace -- $HOME '~' $PWD | string split --no-empty '/')
set -l split_pwd_for_length $split_pwd
set -l split_pwd_for_output $split_pwd
# Anchor first and last directories
set splitPwdForOutput[1] $colorAnchors"$splitPwd[1]"$keepBackgroundColor$colorDirs
set splitPwdForOutput[-1] $colorAnchors"$splitPwd[-1]"$keepBackgroundColor$colorDirs
set split_pwd_for_output[1] $color_anchors"$split_pwd[1]"$keep_background_color$color_dirs
set split_pwd_for_output[-1] $color_anchors"$split_pwd[-1]"$keep_background_color$color_dirs
pwdMaxLength=(math $COLUMNS -$tide_pwd_truncate_margin) i=1 for dirSection in $splitPwd[2..-2]
set -l parentDir (string join -- '/' $splitPwd[1..$i] | string replace '~' $HOME) # Use i from before increment
pwd_max_length=(math $COLUMNS -$tide_pwd_truncate_margin) i=1 for dir_section in $split_pwd[2..-2]
set -l parentDir (string join -- '/' $split_pwd[1..$i] | string replace '~' $HOME) # Use i from before increment
set i (math $i + 1) # This keeps us from using seq
# Returns true if any markers exist in dirSection
if test -z false (string split --max 2 " " -- "-o -e "$parentDir/$dirSection/$tide_pwd_markers)
set splitPwdForOutput[$i] $colorAnchors$dirSection$keepBackgroundColor$colorDirs
else if test (string join -- '/' $splitPwdForLength | string length) -gt $pwdMaxLength
while set -l truncationLength (math $truncationLength + 1) &&
set -l truncated (string sub --length $truncationLength -- $dirSection) &&
test $truncated != $dirSection -a (count $parentDir/$truncated*/) -gt 1
# Returns true if any markers exist in dir_section
if test -z false (string split --max 2 " " -- "-o -e "$parentDir/$dir_section/$tide_pwd_markers)
set split_pwd_for_output[$i] $color_anchors$dir_section$keep_background_color$color_dirs
else if test (string join -- '/' $split_pwd_for_length | string length) -gt $pwd_max_length
while set -l truncation_length (math $truncation_length + 1) &&
set -l truncated (string sub --length $truncation_length -- $dir_section) &&
test $truncated != $dir_section -a (count $parentDir/$truncated*/) -gt 1
end
set splitPwdForLength[$i] $truncated
set splitPwdForOutput[$i] $colorTruncatedDirs$truncated$keepBackgroundColor$colorDirs
set split_pwd_for_length[$i] $truncated
set split_pwd_for_output[$i] $color_truncated_dirs$truncated$keep_background_color$color_dirs
end
end
# Printing logic
test "$splitPwd[1]" = '~' || set splitPwdForOutput[1] '/'$splitPwdForOutput[1]
test "$split_pwd[1]" = '~' || set split_pwd_for_output[1] '/'$split_pwd_for_output[1]
if not test -w $PWD
_tide_print_item pwd $colorDirs$tide_pwd_unwritable_icon' ' (string join -- / $splitPwdForOutput)
_tide_print_item pwd $color_dirs$tide_pwd_unwritable_icon' ' (string join -- / $split_pwd_for_output)
else if test $PWD = $HOME
_tide_print_item pwd $colorDirs$tide_pwd_home_icon' ' (string join -- / $splitPwdForOutput)
_tide_print_item pwd $color_dirs$tide_pwd_home_icon' ' (string join -- / $split_pwd_for_output)
else
_tide_print_item pwd $colorDirs$tide_pwd_dir_icon' ' (string join -- / $splitPwdForOutput)
_tide_print_item pwd $color_dirs$tide_pwd_dir_icon' ' (string join -- / $split_pwd_for_output)
end
end

View File

@ -1,7 +1,8 @@
function _tide_item_virtual_env
set -l splitVirtualEnv (string split '/' "$VIRTUAL_ENV") && if contains -- $splitVirtualEnv[-1] virtualenv venv .venv env
_tide_print_item virtual_env $tide_virtual_env_icon' ' $splitVirtualEnv[-2]
else
_tide_print_item virtual_env $tide_virtual_env_icon' ' $splitVirtualEnv[-1]
end
set -l split_virtual_env (string split '/' "$VIRTUAL_ENV") &&
if contains -- $split_virtual_env[-1] virtualenv venv .venv env # avoid generic names
_tide_print_item virtual_env $tide_virtual_env_icon' ' $split_virtual_env[-2]
else
_tide_print_item virtual_env $tide_virtual_env_icon' ' $split_virtual_env[-1]
end
end

View File

@ -1,31 +1,31 @@
function _tide_print_item -a item
itemBgColorName=tide_"$item"_bg_color set itemBgColor $$itemBgColorName
item_bg_color_name=tide_"$item"_bg_color set item_bg_color $$item_bg_color_name
if test "$_tide_which_side_working_on" = left
if test "$_tide_last_item" = newline
if test "$item" != character
set_color $itemBgColor -b normal
set_color $item_bg_color -b normal
printf '%s' $tide_left_prompt_prefix
end
else if test "$itemBgColor" = "$_tide_previous_bg_color"
else if test "$item_bg_color" = "$_tide_previous_bg_color"
set_color $tide_left_prompt_item_separator_same_color_color
printf '%s' $tide_left_prompt_item_separator_same_color
else
set_color $_tide_previous_bg_color -b $itemBgColor
set_color $_tide_previous_bg_color -b $item_bg_color
printf '%s' $tide_left_prompt_item_separator_diff_color
end
else if test "$_tide_last_item" = newline
set_color $itemBgColor -b normal
set_color $item_bg_color -b normal
printf '%s' $tide_right_prompt_prefix
else if test "$itemBgColor" = "$_tide_previous_bg_color"
else if test "$item_bg_color" = "$_tide_previous_bg_color"
set_color $tide_right_prompt_item_separator_same_color_color
printf '%s' $tide_right_prompt_item_separator_same_color
else
set_color $itemBgColor -b $_tide_previous_bg_color
set_color $item_bg_color -b $_tide_previous_bg_color
printf '%s' $tide_right_prompt_item_separator_diff_color
end
itemColorName=tide_"$item"_color set_color $$itemColorName -b $itemBgColor
item_color_name=tide_"$item"_color set_color $$itemColorName -b $item_bg_color
if test "$tide_prompt_pad_items" = true -a "$item" != character
printf '%s' ' ' $argv[2..] ' '
@ -33,6 +33,6 @@ function _tide_print_item -a item
printf '%s' $argv[2..]
end
set -g _tide_previous_bg_color $itemBgColor
set -g _tide_previous_bg_color $item_bg_color
set -g _tide_last_item $item
end

View File

@ -4,28 +4,28 @@ function _tide_prompt
test "$tide_prompt_add_newline_before" = true && echo
leftPrompt=(_tide_left_prompt) rightPrompt=(_tide_right_prompt) if set -q leftPrompt[2] # If the prompt is two lines
set -l promptAndFrameColor (set_color $tide_prompt_frame_and_connection_color -b normal || echo)
left_prompt=(_tide_left_prompt) right_prompt=(_tide_right_prompt) if set -q left_prompt[2] # If the prompt is two lines
set -l prompt_and_frame_color (set_color $tide_prompt_frame_and_connection_color -b normal || echo)
if test "$tide_left_prompt_frame_enabled" = true
set leftPrompt[1] $promptAndFrameColor╭─"$leftPrompt[1]"
set leftPrompt[2] $promptAndFrameColor╰─"$leftPrompt[2]"
set left_prompt[1] $prompt_and_frame_color╭─"$left_prompt[1]"
set left_prompt[2] $prompt_and_frame_color╰─"$left_prompt[2]"
end
if test "$tide_right_prompt_frame_enabled" = true
set rightPrompt[1] "$rightPrompt[1]"$promptAndFrameColor─╮
set rightPrompt[2] "$rightPrompt[2]"$promptAndFrameColor─╯
set right_prompt[1] "$right_prompt[1]"$prompt_and_frame_color─╮
set right_prompt[2] "$right_prompt[2]"$prompt_and_frame_color─╯
end
printf '%s' $leftPrompt[1] $promptAndFrameColor
printf '%s' $left_prompt[1] $prompt_and_frame_color
set -l lengthToMove (math $COLUMNS - (_tide_decolor "$leftPrompt[1]""$rightPrompt[1]" | string length))
test $lengthToMove -gt 0 && string repeat --no-newline --max $lengthToMove $tide_prompt_connection_icon
set -l length_to_move (math $COLUMNS - (_tide_decolor "$left_prompt[1]""$right_prompt[1]" | string length))
test $length_to_move -gt 0 && string repeat --no-newline --max $length_to_move $tide_prompt_connection_icon
printf '%s' $rightPrompt[1] \n $leftPrompt[-1]' '
set -U $_tide_right_prompt_display_var $rightPrompt[2]
printf '%s' $right_prompt[1] \n $left_prompt[-1]' '
set -U $_tide_right_prompt_display_var $right_prompt[2]
else
printf '%s' $leftPrompt[-1]' '
set -U $_tide_right_prompt_display_var $rightPrompt[1]
printf '%s' $left_prompt[-1]' '
set -U $_tide_right_prompt_display_var $right_prompt[1]
end
end

View File

@ -1,13 +1,13 @@
function _tide_remove_unusable_items
# Remove tool-specific items for tools the machine doesn't have installed
for item in chruby git nvm php rustc virtual_env
set -l cliName $item
set -l cli_name $item
switch $item
case virtual_env
set cliName python
set cli_name python
end
if not type -q $cliName
if not type -q $cli_name
_tide_find_and_remove $item tide_left_prompt_items
_tide_find_and_remove $item tide_right_prompt_items
end

View File

@ -10,11 +10,11 @@ function _tide_sub_bug-report
string match --regex --invert "^_tide_.*_prompt_display_.*" | # Remove _tide_left_prompt_display_5770 etc
string match --regex --invert "^_tide_var_list.*" # Remove _tide_var_list
else
set -l fishVersion (fish --version | string match --regex "fish, version (\d\.\d\.\d)")[2]
_tide_check_version Fish fish-shell/fish-shell "(\d\.\d\.\d)" $fishVersion || return
set -l fish_version (fish --version | string match --regex "fish, version (\d\.\d\.\d)")[2]
_tide_check_version Fish fish-shell/fish-shell "(\d\.\d\.\d)" $fish_version || return
set -l tideVersion (tide --version | string match --regex "tide, version (\d\.\d\.\d)")[2]
_tide_check_version Tide IlanCosman/tide "v(\d\.\d\.\d)" $tideVersion || return
set -l tide_version (tide --version | string match --regex "tide, version (\d\.\d\.\d)")[2]
_tide_check_version Tide IlanCosman/tide "v(\d\.\d\.\d)" $tide_version || return
# Check that omf is not installed
not functions --query omf
@ -23,26 +23,26 @@ function _tide_sub_bug-report
"Please uninstall it before submitting a bug report." || return
read --local --prompt-str "What operating system are you using? (e.g Ubuntu 20.04): " os
read --local --prompt-str "What terminal emulator are you using? (e.g Kitty): " terminalEmulator
read --local --prompt-str "What terminal emulator are you using? (e.g Kitty): " terminal_emulator
printf '%b\n' "\nPlease copy the following information into the issue:\n" \
"fish version: $fishVersion" \
"tide version: $tideVersion" \
"fish version: $fish_version" \
"tide version: $tide_version" \
"term: $TERM" \
"os: $os" \
"terminal emulator: $terminalEmulator"
"terminal emulator: $terminal_emulator"
end
end
function _tide_check_version -a programName repoName regexToGetVersion currentVersion
curl --silent https://github.com/$repoName/releases/latest |
string match --regex ".*$repoName/releases/tag/$regexToGetVersion.*" |
function _tide_check_version -a program_name repo_name regex_to_get_version current_version
curl --silent https://github.com/$repo_name/releases/latest |
string match --regex ".*$repo_name/releases/tag/$regex_to_get_version.*" |
read --local --line __ latestVersion
string match --quiet --regex "^$latestVersion" "$currentVersion"
string match --quiet --regex "^$latestVersion" "$current_version"
_tide_check_condition \
"Your $programName version is out of date." \
"The latest is $latestVersion. You have $currentVersion." \
"Your $program_name version is out of date." \
"The latest is $latestVersion. You have $current_version." \
"Please update before submitting a bug report."
end

View File

@ -44,7 +44,7 @@ function _tide_option -a symbol text
end
function _tide_menu
set -l listWithSlashes (string join '/' $_tide_option_list)
set -l list_with_slashes (string join '/' $_tide_option_list)
printf '%s\n' \
'(r) Restart from the beginning' \
@ -52,7 +52,7 @@ function _tide_menu
while true
set_color -o
read --prompt-str "Choice [$listWithSlashes/r/q] " input
read --prompt-str "Choice [$list_with_slashes/r/q] " input
set_color normal
switch $input