visidata icon indicating copy to clipboard operation
visidata copied to clipboard

Add zsh completion

Open Freed-Wu opened this issue 1 year ago • 0 comments

This is continuation of #1342, however, visidata don't use argparse, so it is a little challengous (at least for me :cry:, can any one help?) to write completion script for it. Now it is just a simple method, which don't contain prompt, completion, etc like https://github.com/saulpw/visidata/pull/1342/files#diff-69dc3db00b91df6e81f3d487b5c2337436c239aa9eae4940ad3546d847249084.

#compdef vd visidata

(( $+functions[_vd_files] )) ||
_vd_files () {
  case $PREFIX in
    (*) _files $* ;;
  esac
  case $PREFIX in
    (+) _message -e 'toplevel:subsheet:col:row' ;;
    (+<1->) _message -e 'toplevel' ;;
    (+<1->:) _message -e 'subsheet' ;;
    (+<1->:<1->:) _message -e 'col' ;;
    (+<1->:<1->:<1->:) _message -e 'row' ;;
  esac
}

_arguments -S \
    '--visidata_dir' \
    '--disp_splitwin_pct' \
    '--mouse_interval' \
    '--color_sidebar' \
    '--null_value' \
    '--undo' \
    '--disp_currency_fmt' \
    '--disp_float_fmt' \
    '--disp_int_fmt' \
    '--disp_date_fmt' \
    '--col_cache_size' \
    '--clean_names' \
    '--default_width' \
    '--default_height' \
    '--textwrap_cells' \
    '--quitguard' \
    '--debug' \
    '--skip' \
    '--header' \
    '--load_lazy' \
    '--force_256_colors' \
    '--disp_note_none' \
    '--disp_truncator' \
    '--disp_oddspace' \
    '--disp_more_left' \
    '--disp_more_right' \
    '--disp_error_val' \
    '--disp_ambig_width' \
    '--disp_pending' \
    '--note_pending' \
    '--note_format_exc' \
    '--note_getter_exc' \
    '--note_type_exc' \
    '--color_note_pending' \
    '--color_note_type' \
    '--color_note_row' \
    '--scroll_incr' \
    '--disp_column_sep' \
    '--disp_keycol_sep' \
    '--disp_rowtop_sep' \
    '--disp_rowmid_sep' \
    '--disp_rowbot_sep' \
    '--disp_rowend_sep' \
    '--disp_keytop_sep' \
    '--disp_keymid_sep' \
    '--disp_keybot_sep' \
    '--disp_endtop_sep' \
    '--disp_endmid_sep' \
    '--disp_endbot_sep' \
    '--disp_selected_note' \
    '--disp_sort_asc' \
    '--disp_sort_desc' \
    '--color_default' \
    '--color_default_hdr' \
    '--color_bottom_hdr' \
    '--color_current_row' \
    '--color_current_col' \
    '--color_current_hdr' \
    '--color_column_sep' \
    '--color_key_col' \
    '--color_hidden_col' \
    '--color_selected_row' \
    '--name_joiner' \
    '--value_joiner' \
    '--disp_rstatus_fmt' \
    '--disp_status_fmt' \
    '--disp_lstatus_max' \
    '--disp_status_sep' \
    '--color_keystrokes' \
    '--color_status' \
    '--color_error' \
    '--color_warning' \
    '--color_top_status' \
    '--color_active_status' \
    '--color_inactive_status' \
    '--wrap' \
    '--save_filetype' \
    '--profile' \
    '--min_memory_mb' \
    '--color_working' \
    '--encoding' \
    '--encoding_errors' \
    '--color_edit_cell' \
    '--disp_edit_fill' \
    '--disp_unprintable' \
    '--input_history' \
    '--bulk_select_clear' \
    '--some_selected_rows' \
    '--delimiter' \
    '--row_delimiter' \
    '--tsv_safe_newline' \
    '--tsv_safe_tab' \
    '--visibility' \
    '--default_sample_size' \
    '--json_indent' \
    '--json_sort_keys' \
    '--default_colname' \
    '--filetype' \
    '--confirm_overwrite' \
    '--safe_error' \
    '--disp_formatter' \
    '--clipboard_copy_cmd' \
    '--clipboard_paste_cmd' \
    '--disp_menu' \
    '--disp_menu_keys' \
    '--color_menu' \
    '--color_menu_active' \
    '--color_menu_spec' \
    '--color_menu_help' \
    '--disp_menu_boxchars' \
    '--disp_menu_more' \
    '--disp_menu_push' \
    '--disp_menu_input' \
    '--disp_menu_fmt' \
    '--fancy_chooser' \
    '--describe_aggrs' \
    '--disp_histogram' \
    '--disp_histolen' \
    '--histogram_bins' \
    '--numeric_binning' \
    '--replay_wait' \
    '--disp_replay_play' \
    '--disp_replay_pause' \
    '--color_status_replay' \
    '--replay_movement' \
    '--rowkey_prefix' \
    '--cmdlog_histfile' \
    '--regex_flags' \
    '--regex_maxsplit' \
    '--show_graph_labels' \
    '--plot_colors' \
    '--disp_canvas_charset' \
    '--disp_pixel_random' \
    '--zoom_incr' \
    '--color_graph_hidden' \
    '--color_graph_selected' \
    '--color_graph_axis' \
    '--motd_url' \
    '--dir_recurse' \
    '--dir_hidden' \
    '--config' \
    '--play' \
    '--batch' \
    '--output' \
    '--preplay' \
    '--imports' \
    '--color_add_pending' \
    '--color_change_pending' \
    '--color_delete_pending' \
    '--unfurl_empty' \
    '--incr_base' \
    '--csv_dialect' \
    '--csv_delimiter' \
    '--csv_quotechar' \
    '--csv_skipinitialspace' \
    '--csv_escapechar' \
    '--csv_lineterminator' \
    '--safety_first' \
    '--xlsx_meta_columns' \
    '--fixed_rows' \
    '--fixed_maxcols' \
    '--postgres_schema' \
    '--http_max_next' \
    '--http_req_headers' \
    '--html_title' \
    '--pcap_internet' \
    '--graphviz_edge_labels' \
    '--npy_allow_pickle' \
    '--pdf_tables' \
    '--color_xword_active' \
    '--plugins_url' \
    '--plugins_autoload' \
    '*:file:_vd_files'

Freed-Wu avatar Aug 04 '22 15:08 Freed-Wu

If users use package manager to install this program, such as apt install or pacman -S, they don't need to any work. The packager will do this work for users.

If users install this package by ./setup.py install or pip install, they should do some work by themselves:

  1. run zsh_completion.py to generate _visidata
  2. cp _visidata /usr/share/zsh/site-functions

Freed-Wu avatar Aug 12 '22 23:08 Freed-Wu

Hey @Freed-Wu!

I tried following those instructions, but I do not believe I have zsh completion working for VisiData.

I have:

-rwxr-xr-x 1 root root 16K Aug 15 22:08 /usr/share/zsh/functions/_visidata

And / usr/share/zsh/functions/_visidata is in my $fpath.

And vd --q <TAB> does not autocomplete to anything. Can you tell what I might be doing wrong?

anjakefala avatar Aug 16 '22 05:08 anjakefala

❯ dev/zsh_completion.py
❯ sudo mv _visidata /usr/share/zsh/site-functions
# update ~/.zcompdump. ususally write it to your ~/.zshrc to make sure every 
# time you start zsh it will be conducted automatically
❯ zcompinit
❯ grep -n visidata ~/.zcompdump
1575:'vd' '_visidata'
1585:'visidata' '_visidata'
1913:            _updpkgsums _vagrant _virtualbox _visidata _vnstat \

Freed-Wu avatar Aug 16 '22 11:08 Freed-Wu

For me I had to

sudo mv _visidata /usr/local/share/zsh/site-functions
compinit

And now, this is working great! =)

anjakefala avatar Aug 17 '22 05:08 anjakefala

The docs will be pushed to https://visidata.org on the next VisiData release. =)

Thank you so much for your dedication to this problem @Freed-Wu!

anjakefala avatar Aug 17 '22 05:08 anjakefala

Great! :+1:

Freed-Wu avatar Aug 17 '22 06:08 Freed-Wu