From a5029f0b8e5fdd0ee212630dd47c2677a72f73e8 Mon Sep 17 00:00:00 2001 From: Wu Zhenyu Date: Thu, 27 Apr 2023 16:08:20 +0800 Subject: [PATCH] Add zsh completion, fix #4058 --- CMakeLists.txt | 2 ++ Makefile.am | 2 +- contrib/Makefile.am | 4 +++ contrib/completions/zsh/_tesseract | 45 ++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 contrib/Makefile.am create mode 100644 contrib/completions/zsh/_tesseract diff --git a/CMakeLists.txt b/CMakeLists.txt index db4c39d586..fff58a6195 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -961,6 +961,8 @@ if(INSTALL_CONFIGS) DESTINATION ${CMAKE_INSTALL_PREFIX}/share/tessdata/configs) install(FILES ${TESSERACT_TESSCONFIGS} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/tessdata/tessconfigs) + install(FILES contrib/completions/zsh/_tesseract + DESTINATION ${CMAKE_INSTALL_PREFIX}/share/zsh/site-functions) endif() # ############################################################################## diff --git a/Makefile.am b/Makefile.am index f9c48dea43..a537a38459 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,7 @@ ACLOCAL_AMFLAGS = -I m4 CLEANFILES = -SUBDIRS = . tessdata +SUBDIRS = . tessdata contrib EXTRA_DIST = README.md LICENSE EXTRA_DIST += aclocal.m4 config configure.ac autogen.sh diff --git a/contrib/Makefile.am b/contrib/Makefile.am new file mode 100644 index 0000000000..9db762c8b6 --- /dev/null +++ b/contrib/Makefile.am @@ -0,0 +1,4 @@ +zshcompletiondir = @datadir@/zsh/site-functions +zshcompletion_DATA = completions/zsh/_tesseract + +EXTRA_DIST = $(zshcompletion_DATA) diff --git a/contrib/completions/zsh/_tesseract b/contrib/completions/zsh/_tesseract new file mode 100644 index 0000000000..248c557093 --- /dev/null +++ b/contrib/completions/zsh/_tesseract @@ -0,0 +1,45 @@ +#compdef tesseract + +local psm=( + '0\:Orientation\ and\ script\ detection\ \(OSD\)\ only' + '1\:Automatic\ page\ segmentation\ with\ OSD' + '2\:Automatic\ page\ segmentation,\ but\ no\ OSD,\ or\ OCR\ \(not\ implemented\)' + '3\:Fully\ automatic\ page\ segmentation,\ but\ no\ OSD\ \(Default\)' + '4\:Assume\ a\ single\ column\ of\ text\ of\ variable\ sizes' + '5\:Assume\ a\ single\ uniform\ block\ of\ vertically\ aligned\ text' + '6\:Assume\ a\ single\ uniform\ block\ of\ text' + '7\:Treat\ the\ image\ as\ a\ single\ text\ line' + '8\:Treat\ the\ image\ as\ a\ single\ word' + '9\:Treat\ the\ image\ as\ a\ single\ word\ in\ a\ circle' + '10\:Treat\ the\ image\ as\ a\ single\ character' + '11\:Sparse\ text.\ Find\ as\ much\ text\ as\ possible\ in\ no\ particular\ order' + '12\:Sparse\ text\ with\ OSD' + '13\:Raw\ line.\ Treat\ the\ image\ as\ a\ single\ text\ line,\ bypassing\ hacks\ that\ are\ Tesseract-specific' +) +local oem=( + '0\:Legacy\ engine\ only' + '1\:Neural\ nets\ LSTM\ engine\ only' + '2\:Legacy\ +\ LSTM\ engines' + '3\:Default,\ based\ on\ what\ is\ available' +) +local options=( + "(- : *)"{-h,--help}"[Show minimal help message]" + "(- : *)"--help-extra"[Show extra help for advanced users]" + "(- : *)"--help-psm"[Show page segmentation modes]" + "(- : *)"--help-oem"[Show OCR Engine modes]" + "(- : *)"{-v,--version}"[Show version information]" + "(- : *)"--list-langs"[List available languages for tesseract engine]" + "(- : *)"--print-fonts-table"[Print tesseract fonts table]" + "(- : *)"--print-parameters"[Print tesseract parameters]" + --tessdata-dir"[Specify the location of tessdata path]: :_dirs" + --user-words"[Specify the location of user words file]: :_files" + --user-patterns"[Specify the location of user patterns file]: :_files" + --dpi"[Specify DPI for input image]:VALUE" + --loglevel"[Specify logging level]:LEVEL:(ALL TRACE DEBUG INFO WARN ERROR FATAL OFF)" + -l"[Specify language(s) used for OCR]:LANG:($(tesseract --list-langs | tail -n+2))" + '*'-c"[Set value for config variables]:VAR=VALUE" + --psm"[Specify page segmentation mode]:Page segmentation mode:(($psm))" + --oem"[Specify OCR Engine mode]:OCR Engine mode:(($oem))" +) + +_arguments -s -S $options ':imagename:_files' ':outputbase:_files' '*:config:_files'