Ed Page
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Clap Completion Requirements ## bash Bash's expectations Inputs for `-F` and `-C`: - COMP_LINE: The current command line. This variable is available only in shell functions and external commands invoked by the programmable completion facilities - COMP_POINT: The index of the current cursor position relative to the beginning of the current command. If the current cursor position is at the end of the current command, the value of this variable is equal to ${#COMP_LINE}. This variable is available only in shell functions and external commands invoked by the programmable completion facilities - COMP_KEY: The key (or final key of a key sequence) used to invoke the current completion function. - COMP_TYPE: Set to an integer value corresponding to the type of completion attempted that caused a completion function to be called: TAB, for normal completion, ‘?’, for listing completions after successive tabs, ‘!’, for listing alternatives on partial word completion, ‘@’, to list completions if the word is not unmodified, or ‘%’, for menu completion. This variable is available only in shell functions and external commands invoked by the programmable completion facilities - 1: name of the command whose arguments are being completed - 2: word being completed - 3: word preceding the word being completed on the current command line Inputs for `-F`: - COMP_WORDS, COMP_CWORD when used with `-F` Output for `-C`: - print a list of completions, one per line, to the standard output. Backslash may be used to escape a newline, if necessary. Output for `-F`: - It must put the possible completions in the COMPREPLY array variable, one per array element. See - https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion - https://www.gnu.org/software/bash/manual/html_node/A-Programmable-Completion-Example.html#A-Programmable-Completion-Example - https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins - https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html ### clap_complete ```bash= _clap_complete_NAME() { local IFS=$'\013' local SUPPRESS_SPACE=0 if compopt +o nospace 2> /dev/null; then SUPPRESS_SPACE=1 fi if [[ ${SUPPRESS_SPACE} == 1 ]]; then SPACE_ARG="--no-space" else SPACE_ARG="--space" fi COMPREPLY=( $("COMPLETER" complete --index ${COMP_CWORD} --type ${COMP_TYPE} ${SPACE_ARG} --ifs="$IFS" -- "${COMP_WORDS[@]}") ) if [[ $? != 0 ]]; then unset COMPREPLY elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then compopt -o nospace fi } complete OPTIONS -F _clap_complete_NAME EXECUTABLES ``` - Command line (COMP_WORDS) is passed after `--` - We complete the argument at argument index specified via `--index COMP_CWORD` - We could get the char (or byte?) index to complete at but that gets more complicated to parse - `SUPPRESS_SPACE` / `--[no-]space` isn't something I fully understand how we should be handling at the moment - `--type COMP_TYPE` isn't something I fully understand how we should be handling at the moment ## fish ### registration Fish shell only suports dynamic arguments not flags (https://github.com/fish-shell/fish-shell/issues/7943), therefore all flag specific logic needs to be implemented manually. This snippet expects the completion logic implemented in https://github.com/clap-rs/clap/pull/4177. ```fish complete -x -c {name} -a "{name} complete --previous=(commandline --current-process --tokenize --cut-at-cursor) --current (commandline --current-token)" ``` ### requirements of returned completions - Only return short flags, when the current token starts with `-` - When returning short flags provide completions with an additional joined flag: * Given the short flags a, b, c * When the current token is -b provide the completions -ba and -bc * Display the help of the added flag i.e. a or c - Only return long flags when the current token starts with `--` * Return help/about tab seperated from the completion item ### Prior Art argcomplete emulates bash's interface in fish by ``` set -x COMP_LINE (commandline -p) set -x COMP_POINT (string length (commandline -cp)) set -x COMP_TYPE ``` and then just registers that function https://github.com/kislyuk/argcomplete/blob/develop/argcomplete/shell_integration.py#L60 [cobra](https://github.com/spf13/cobra): TBD [bpaf](https://github.com/pacak/bpaf): TBD - https://github.com/pacak/bpaf/blob/master/src/complete_run.rs - https://github.com/pacak/bpaf/blob/master/src/complete_gen.rs # Proposed shared interface This interface would allow the dynamic bash completions to be the same as it is currently, and support almost the full fish feature ## Necessary flags - `separator` character used to seperate returned completions e.g. `\n` for fish and `\013` for bash. (Maybe make newline the default) - `current` the word the curser is on when triggering completions, leave empty when cursor not on word e.g. `COMP_WORDS[COMP_CWORD]` for bash and `commandline --current-token` - `preceding` all tokens making up the command preceding the token containing the cursor e.g. `COMP_WORDS[@]::COMP_CWORD` for bash and `commandline --current-process --tokenize --cut-at-cursor` for fish - `help-seperator` seperater to put between completion item and help/about text `\t` for fish (Optional if not set no help will be returned) - `short-flag-joining` support joining multiple short flags via completions i.e. will return -ra as a completion if the current token is -r ### starts with dash condition for flags #### decision in clap - `flags-require-dash` only return short flags when current token starts with `-` and long flags if current token starts with `--` #### decision in shell - `show-short` e.g. for fish `commandline --current-token | string match -- "--*"` - `show-long` e.g. for fish `commandline --current-token | string match -r -- "^-[^-]"` ### Shell native like path completions #### Emulate in clap Probably not a great idea as e.g. fish does quite a lot here: - expand globs: `*/ba` would complete to `*/bash.rs` and `*/banana.rs` (given the paths `a/bash.rs` and `b/bash.rs`) - complete substrings (not only prefixes) `rc/he/ba` would complete to `src/shell/bash.rs`. #### pass path completions in Prefered, but requires us to allow `*` in the paths returned from fish - `paths` optional, completes current token as path if not present we do our own basic path completions e.g. for fish `complete -C "__fish_complete_path "(commandline --current-token)` (ideally this would be `__fish_complete_path (commandline --current-token)` but that is currently not supported fully: [fish-shell/fish-shell#9285](https://github.com/fish-shell/fish-shell/issues/9285)) - `paths-allow-fish-globs` allows `*` and `?` in paths used for completions (only has impact when `paths` is provided), only necessary to implement filtering could be skipped at first. #### have a complete files/dirs query flag Not ideal as it removes us from the ability to filter the results - `should-complete-path` exits with 0 when the next argument should be a path ## Potential flags These are the flags the current bash implementation taking, but don't have any implementation yet. I'd skip them for now. * `comp-type` * `space`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully