mirror of
https://github.com/IlanCosman/tide.git
synced 2024-12-23 12:03:48 +03:00
Remove unusable tool items on startup (fixes #129)
This commit is contained in:
parent
4a00b7fe79
commit
9e7f04d82e
@ -1,10 +1,12 @@
|
||||
status is-interactive || exit
|
||||
|
||||
# Set things that wont change
|
||||
_tide_remove_unusable_items
|
||||
_tide_detect_os
|
||||
|
||||
set -g _tide_left_prompt_display_var _tide_left_prompt_display_$fish_pid
|
||||
set -g _tide_right_prompt_display_var _tide_right_prompt_display_$fish_pid
|
||||
set -gx _tide_fish_pid $fish_pid
|
||||
_tide_detect_os
|
||||
|
||||
function _tide_background_job --on-event fish_prompt --on-variable fish_bind_mode
|
||||
_tide_last_pipestatus=$pipestatus _tide_jobs_number=(jobs --pid | count) fish --command "
|
||||
|
3
functions/_tide_find_and_remove.fish
Normal file
3
functions/_tide_find_and_remove.fish
Normal file
@ -0,0 +1,3 @@
|
||||
function _tide_find_and_remove -a name list --no-scope-shadowing
|
||||
set -e "$list"[(contains --index $name $$list)] 2>/dev/null # Ignore error if $list doesn't contain $name
|
||||
end
|
24
functions/_tide_remove_unusable_items.fish
Normal file
24
functions/_tide_remove_unusable_items.fish
Normal file
@ -0,0 +1,24 @@
|
||||
function _tide_remove_unusable_items
|
||||
argparse f/fake -- $argv
|
||||
|
||||
# Remove tool-specific items for tools the machine doesn't have installed
|
||||
for item in chruby git nvm php rust virtual_env
|
||||
set -l cliName $item
|
||||
switch $item
|
||||
case virtual_env
|
||||
set cliName python
|
||||
case rust
|
||||
set cliName rustc
|
||||
end
|
||||
|
||||
if not type -q $cliName
|
||||
if set -q _flag_fake
|
||||
_tide_find_and_remove $item fake_tide_left_prompt_items
|
||||
_tide_find_and_remove $item fake_tide_right_prompt_items
|
||||
else
|
||||
_tide_find_and_remove $item tide_left_prompt_items
|
||||
_tide_find_and_remove $item tide_right_prompt_items
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -79,10 +79,6 @@ function _tide_display_prompt -a var_name var_value
|
||||
printf '\n\n'
|
||||
end
|
||||
|
||||
function _find_and_remove -a name list --no-scope-shadowing
|
||||
set -e "$list"[(contains --index $name $$list)] 2>/dev/null # Ignore error if $list doesn't contain $name
|
||||
end
|
||||
|
||||
function _set_all_items_bg_color -a color
|
||||
for var in (set --names | string match --regex "fake_.*_bg_color")
|
||||
set $var $color
|
||||
|
@ -17,34 +17,14 @@ function finish
|
||||
end
|
||||
|
||||
function _tide_finish
|
||||
# Remove tool-specific items for tools the machine doesn't have installed
|
||||
set -l generalItems cmd_duration context jobs os prompt_char pwd status time vi_mode
|
||||
set -l toolSpecificItems (functions --all | string replace --filter --regex "^_tide_item_" '')
|
||||
for item in $generalItems
|
||||
_find_and_remove $item toolSpecificItems
|
||||
end
|
||||
|
||||
for item in $toolSpecificItems
|
||||
set -l cliName $item
|
||||
switch $item
|
||||
case virtual_env
|
||||
set cliName python
|
||||
case rust
|
||||
set cliName rustc
|
||||
end
|
||||
|
||||
if not type -q $cliName
|
||||
_find_and_remove $item fake_tide_left_prompt_items
|
||||
_find_and_remove $item fake_tide_right_prompt_items
|
||||
end
|
||||
end
|
||||
_tide_remove_unusable_items --fake
|
||||
|
||||
# Deal with prompt char/vi mode
|
||||
if contains prompt_char $fake_tide_left_prompt_items
|
||||
_find_and_remove vi_mode fake_tide_right_prompt_items
|
||||
_tide_find_and_remove vi_mode fake_tide_right_prompt_items
|
||||
else
|
||||
# If no prompt_char, insert vi_mode
|
||||
_find_and_remove vi_mode fake_tide_right_prompt_items
|
||||
_tide_find_and_remove vi_mode fake_tide_right_prompt_items
|
||||
if contains time $fake_tide_right_prompt_items
|
||||
set fake_tide_right_prompt_items $fake_tide_right_prompt_items[1..-2] vi_mode $fake_tide_right_prompt_items[-1]
|
||||
else
|
||||
|
@ -24,7 +24,7 @@ function _enable_icons
|
||||
end
|
||||
|
||||
function _disable_icons
|
||||
_find_and_remove os fake_tide_left_prompt_items
|
||||
_tide_find_and_remove os fake_tide_left_prompt_items
|
||||
set fake_tide_pwd_dir_icon
|
||||
set fake_tide_pwd_home_icon
|
||||
set fake_tide_cmd_duration_icon
|
||||
|
@ -2,7 +2,7 @@ function lean_prompt_height
|
||||
_tide_title 'Prompt Height'
|
||||
|
||||
_tide_option 1 'One line'
|
||||
_find_and_remove newline fake_tide_left_prompt_items
|
||||
_tide_find_and_remove newline fake_tide_left_prompt_items
|
||||
_tide_display_prompt
|
||||
|
||||
_tide_option 2 'Two lines'
|
||||
@ -12,10 +12,10 @@ function lean_prompt_height
|
||||
_tide_menu
|
||||
switch $_tide_selected_option
|
||||
case 1
|
||||
_find_and_remove newline fake_tide_left_prompt_items
|
||||
_tide_find_and_remove newline fake_tide_left_prompt_items
|
||||
_next_choice all/prompt_connection_andor_frame_color
|
||||
case 2
|
||||
_find_and_remove newline fake_tide_left_prompt_items
|
||||
_tide_find_and_remove newline fake_tide_left_prompt_items
|
||||
set -g fake_tide_left_prompt_items $fake_tide_left_prompt_items[1..-2] newline $fake_tide_left_prompt_items[-1]
|
||||
_next_choice all/prompt_connection
|
||||
end
|
||||
|
@ -2,7 +2,7 @@ function powerline_prompt_height
|
||||
_tide_title 'Prompt Height'
|
||||
|
||||
_tide_option 1 'One line'
|
||||
_find_and_remove newline fake_tide_left_prompt_items
|
||||
_tide_find_and_remove newline fake_tide_left_prompt_items
|
||||
set fake_tide_left_prompt_frame_enabled false
|
||||
set fake_tide_right_prompt_frame_enabled false
|
||||
_tide_display_prompt
|
||||
@ -16,12 +16,12 @@ function powerline_prompt_height
|
||||
_tide_menu
|
||||
switch $_tide_selected_option
|
||||
case 1
|
||||
_find_and_remove newline fake_tide_left_prompt_items
|
||||
_tide_find_and_remove newline fake_tide_left_prompt_items
|
||||
set fake_tide_left_prompt_frame_enabled false
|
||||
set fake_tide_right_prompt_frame_enabled false
|
||||
_next_choice all/prompt_connection_andor_frame_color
|
||||
case 2
|
||||
_find_and_remove newline fake_tide_left_prompt_items
|
||||
_tide_find_and_remove newline fake_tide_left_prompt_items
|
||||
set -g fake_tide_left_prompt_items $fake_tide_left_prompt_items newline
|
||||
set fake_tide_left_prompt_frame_enabled true
|
||||
set fake_tide_right_prompt_frame_enabled true
|
||||
|
Loading…
Reference in New Issue
Block a user