{"id":13524429,"url":"https://github.com/rcmdnk/sentaku","last_synced_at":"2025-04-05T16:10:11.889Z","repository":{"id":13171763,"uuid":"15854863","full_name":"rcmdnk/sentaku","owner":"rcmdnk","description":"Utility to make sentaku (selection, 選択(sentaku)) window with shell command.","archived":false,"fork":false,"pushed_at":"2024-11-05T14:55:05.000Z","size":340,"stargazers_count":141,"open_issues_count":1,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T15:11:15.442Z","etag":null,"topics":["bash","interactive","selection","shell","terminal"],"latest_commit_sha":null,"homepage":"http://rcmdnk.github.io/blog/2014/01/24/computer-bash-zsh/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rcmdnk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"rcmdnk","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2014-01-13T01:28:27.000Z","updated_at":"2025-01-15T09:40:02.000Z","dependencies_parsed_at":"2024-04-30T09:31:46.978Z","dependency_job_id":"42914926-d815-4093-b803-a00b32ff4b29","html_url":"https://github.com/rcmdnk/sentaku","commit_stats":null,"previous_names":[],"tags_count":67,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcmdnk%2Fsentaku","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcmdnk%2Fsentaku/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcmdnk%2Fsentaku/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcmdnk%2Fsentaku/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rcmdnk","download_url":"https://codeload.github.com/rcmdnk/sentaku/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361693,"owners_count":20926643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","interactive","selection","shell","terminal"],"created_at":"2024-08-01T06:01:09.992Z","updated_at":"2025-04-05T16:10:11.868Z","avatar_url":"https://github.com/rcmdnk.png","language":"Shell","funding_links":["https://github.com/sponsors/rcmdnk"],"categories":["Command Line","Misc","Shell"],"sub_categories":["Dependency Management"],"readme":"sentaku\n=======\n\nUtility to make sentaku (selection, 選択(sentaku)) window with shell command.\n\n![sentaku](http://rcmdnk.github.io/images/post/20140124_sentaku.gif)\n\nIf you give multi-word to sentaku by pipe at command line,\nyou can choose one of them in the sentaku window\nthen selected one will be returned.\n\nRequirement:\n\n- Bash 3.X or later\n- Zsh 4.X or later\n\n## Installation\n\n### Homebrew on Mac\nOn Mac, you can install scripts by [Homebrew](https://github.com/mxcl/homebrew):\n\n    $ brew tap rcmdnk/rcmdnkpac\n    $ brew install sentaku\n\nIf you have [brew file](https://github.com/rcmdnk/homebrew-file), add following lines to Brewfile:\n\n    tap 'rcmdnk/rcmdnkpac'\n    brew 'sentaku'\n\nthen, do:\n\n    $ brew file install\n\nOr if you write like:\n\n    tapall 'rcmdnk/rcmdnkpac'\n\nand do `brew file install`, you will have all useful scripts in\n[rcmdnkpac](https://github.com/rcmdnk/homebrew-rcmdnkpac).\n\nHomebrew installation installs all scripts in `bin` directory including examples.\n\n\n### cURL\n\nYou can also use an install script on the web like:\n\n    $ curl -fsSL https://raw.github.com/rcmdnk/sentaku/install/install.sh| sh\n\nThis will install scripts to `/usr/bin`\nand you may be asked root password.\n\nIf you want to install other directory, do like:\n\n    $ curl -fsSL https://raw.github.com/rcmdnk/sentaku/install/install.sh|  prefix=~/usr/local/ sh\n\nThis method installs only `sentaku` and `ddv`.\n\n### By hand\n\nOr, simply download scripts and set where you like.\n\n## Usage\n\n### Standalone\n\nUse with pipe at command line.\nIf you run sentaku alone, nothing happens.\n\nGive any words to sentaku by pipe.\nThe default separator is `$IFS`.\n\nIf you want to use different separator,\nuse `-s \u003csep\u003e` option.\n\nIn case there any directory/file names which have spaces, use line break as a separator, i.e.:\n\n    $ ls | sentaku -s $'\\n'\n\nIf you want to use input file instead of pipe,\nuse `sentaku -F \u003cfile\u003e`.\n\nOther options and key operations at sentaku window are:\n\n    Usage: sentaku [-HNulapEVcCURLSnvh] [-f \u003cfile\u003e] [-s \u003csep\u003e] [-r \u003cn\u003e] [input variables]\n\n    Arguments:\n      -f \u003cfile\u003e  Set input file\n      -s \u003csep\u003e   Set separator (default: $IFS)\n                 If \u003csep\u003e is \\\"line\\\", \\$'\\\\n' is set as a separator.\n      -H         Force to show a header at sentaku window.\n      -N         No numbers are shown.\n      -u         Use underline to show selected line, instead of highlighting.\n      -l         Show last words instead of starting words for longer lines.\n      -a         Align input list (set selected one to the first).\n      -r \u003cn\u003e     Return nth value directly.\n      -p         Push words to the file.\n      -E         Use Emacs mode\n      -V         Use Vim mode\n      -c         Load functions as a child process in other sentaku process.\n      -C         Show the file content at the list view\n      -R         Show the file content in the right (default: right)\n      -U         Show the file content under the list (default: right)\n      -L         Number of lines to show the file content under the list (default: 10)\n      -S         Open the file under the cursor by ${VISUAL:-less} at s\n                 instead of full line of the selected one\n      -n         Don't run functions, to just source this file\n      -v         Show version\n      -h         Print this HELP and exit\n\n    Key operation at sentaku window\n      Common for all:\n        C-p/C-n  Up/Down.\n        C-u/C-d  Half page down/Half page down.\n        C-b/C-f  Page up/Page down.\n        M-v/C-v  Page up/Page down.\n        C-a/C-e  Go to the beginning/end.\n        C-i/C-o  Move the item up/down.\n        C-x      Quit.\n        C-s      Start/Stop Visual mode (multi-selection).\n        Space    Select/unselect current line for multi-selection.\n                 At Emacs mode or search mode in Vim mode,\n                 it selects when space is pushed twice.\n        Esc      At search mode, first Esc takes it back to normal mode\n                 with selected words.\n                 Second Esc clear search mode.\n                 Visual mode is cleared by first Esc.\n        Enter    Select and Quit.\n\n      For Vim mode:\n        n(any number) Set number. Multi-digit can be used (13, 320, etc...).\n                      Used/reset by other key.\n        k/j      Up/Down (if n is given, n-th up/n-th down).\n        gg/G     Go to top/bottom. (If n is given, move to n-th candidate.)\n        d        Delete current candidate. (in case you use input file.)\n        s        Show detail of current candidate.\n        v        Visual mode, same as C-s\n        /        Search.\n        q        Quit.\n        Others   Nothing happens.\n\n      For Emacs mode:\n        Others   Normal keys start an incremental search.\n\n#### Environment Variables\n\nName| Description| Default\n:--:|:-----------|:------:\nSENTAKU_INPUT_FILE|File used when stdin is not used (overwritten by -f).|\"$HOME/.sentaku_input\"\nSENTAKU_SEPARATOR|Separator(overwritten by -s).|$IFS\nSENTAKU_MAX|Max number to be written to the file (non-stdin usage).|20\nSENTAKU_NOHEADER|Don't show the header (overwritten by -H). 0: show, 1: don't show.|0 (1 for noheader)\nSENTAKU_NONUMBER|Don't show the line number (overwritten by -N). 0: show, 1: don't show.|0 (1 for nonumber)\nSENTAKU_SHOWLAST|Show the number at the end of the line, too (overwritten by -l). 0: don't show, 1: show.|0\nSENTAKU_CONTENT_LINES|Set number of lines to show the file content under the list|10\nSENTAKU_CONTENT_SHOW_UNDER|Set 1 to set default view of the file content as under the list|0\nSENTAKU_CHILD|If this sentaku is child process of parent sentaku or not.|0\nSENTAKU_SEARCH_OPT|Search option, 0: AND (ignore case), 1: AND (case sensitive), 2: starts with (ignore case), 3: starts with (case sensitive).|1\nSENTAKU_KEYMODE|Vim Mode or Emacs Mode, 0: Vim Mode, 1: Emacs Mode (overwritten by -V/-E).| 0\nSENTAKU_DEBUG|If it is 1, `_sf_echo_debug` is executed.|0\n\n#### Vim/Emacs mode\n\nDefault mode is Vim mode, in which you can go up/down with k/j, respectively.\n\nIf you like emacs mode, you use `-E` option,\nor set the value like `export SENTAKU_KEYMODE=1` in your `.bashrc`/`.zshrc`.\nIn this mode, `\u003cC-n\u003e`/`\u003cC-p\u003e` are used for going up/down, respectively (These keys are also available at Vim mode).\nIt has nice feature that you can start incremental search directly\nby pushing any normal keys.\n\n* Simple Examples:\n    * [ex_pipe.sh](https://github.com/rcmdnk/sentaku/blob/master/bin/ex_pipe.sh): Example for Vim mode (Default).\n    * [ex_emacs](https://github.com/rcmdnk/sentaku/blob/master/bin/ex_emacs.sh): Example for Emacs mode.\n\n* Item Up/Down Demo\n\n![item_up_down](http://rcmdnk.github.io/images/post/20140621_sentaku_item_updown.gif)\n\n\n#### Search mode\n\nIf you push `/`, sentaku enters search mode (at Vim mode).\n\nYou can narrow the list by pushing starting characters.\n\nBackspace (`\u003cC-h\u003e`) can be used to delete a character.\nIn addition, `\u003cC-u\u003e` deletes all characters.\n\nYou can select the first of the list (or the last remained one) by the Enter.\n\nIf you push `Esc` while some candidates are remained,\nyou can select them as select window.\n\nWhen you push `Esc` again, the original list will come back.\n\nYou can set search option `SENTAKU_SEARCH_OPT`:\n\n* 0: AND search (smart case, i.e. all lower case word search is case insensitive, otherwise case sensitive) (Default)\n* 1: AND search (case sensitive)\n* 2: Starts with (smart case)\n* 3: Starts with(case sensitive)\n\n* [Search Demo for Vim mode, SENTAKU_KEYMODE = 3](http://rcmdnk.github.io/images/post/20140805_vim_search.gif)\n\n![sentaku_vim](http://rcmdnk.github.io/images/post/20140805_vim_search.gif)\n\n\n* [Search Demo for Emacs mode, SENTAKU_KEYMODE = 1](http://rcmdnk.github.io/images/post/20140805_emacs_search.gif)\n\n![sentaku_emacs](http://rcmdnk.github.io/images/post/20140805_emacs_search.gif)\n\n#### Visual mode (multi-selection)\n\n![sentaku_vim_multi](http://rcmdnk.github.io/images/post/20140805_vim_multi.gif)\n\nBy pushing `Ctrl-s` (or `v` (only Vim mode)),\nyou can start/stop to choose multi-line.\n\nOutput will be separated by `SENTAKU_SEPARATOR` (default is $IFS).\n\nYou can choose non-sequential lines.\n\nIn addition, you can toggle lines by `Space`.\n\n![sentaku_multi](http://rcmdnk.github.io/images/post/20140926_sentaku_multi.gif)\n\n#### Content view\n\n![sentaku_multi](http://rcmdnk.github.io/images/post/20190930_sentakucontentview.gif)\n\n* [sentakuでファイルの中身を選択中に表示する](http://rcmdnk.github.io/blog/2019/09/30/computer-bash-zsh-sentaku/)\n\n### Use as a library\n\nYou can use sentaku as a library for your shell script.\n\nAt sentaku window, all normal keys are assigned to functions like:\n\n* a-z: `_sf_a ()` ~ `_sf_z ()`\n* A-Z: `_sf_A ()` ~ `_sf_z ()`\n* 0-9: `_sf_0 ()` ~ `_sf_9 ()`\n* Ctrl-a - Ctrl-z: `_sf_c_a ()` ~ `_sf_c_z ()`\n\nIn addition following keys are assigned:\n\n* Enter/Space: `_sf_select ()`\n* /: Start Search\n* Esc: Reset Search\n\nFollowing functions have default methods:\n\n* `_sf_0 ()` ~ `_sf_9 ()`\n* `_sf_d ()`/`_sf_g ()`/`_sf_j ()`/`_sf_k ()`/`_sf_q ()`/`_sf_s ()`/`_sf_v ()`/`_sf_G ()`\n* `_sf_c_a ()`/`_sf_c_b ()`/`_sf_c_c ()`/`_sf_c-e ()`/`_sf_c_f ()`/`_sf_c_c_n ()`/`_sf_c_s ()`/`_sf_c_u ()`/`_sf_c_v ()`/`_sf_c_x ()`\n\nAnd others are just set like `_sf_a () { :;}` (do nothing).\n\nIf you simply add new key operation, make a script like:\n\n``` sh\n#!/usr/bin/env bash\n. sentaku -n\n_sf_a () {\n  _sf_echo \"You pushed a!\"\n}\n_sf_main \"$@\"\n```\n\nFirst, load `sentaku` with `-n` option, which don't execute functions here.\n\nThen, add your functions.\n\nIn the last, call `_sf_main` function with arguments (`$@`).\n\nSave this script as `my_sentaku.sh`, then you can use it as same as\noriginal sentaku command.\nIn addition, you can see `You pushed a!` when you push `a`.\nTo show something, use `_sf_echo` instead of `echo`.\n\nYou can define functions instead of making scripts, too.\n\nIn **.bashrc** or **.zshrc**,\nadd\n\n``` sh\nmy_sentaku () {\n  (\n    . sentaku -n\n\n    _sf_a () {\n      _sf_echo \"You pushed a!\"\n    }\n\n    _sf_main \"$@\"\n  )\n}\n```\n\nthen you can use `my_sentaku` with your `_sf_a` instead of `sentaku`.\n\nNote: Use sub shell (define function content in `()`)\nbecause `. sentaku -n` loads a lot of functions\nand it is better to avoid making current environment dirty.\n\nMore examples can be found below.\n\n#### Simple examples to use like snippet\n\nThe easiest examples are:\n\n* [ex_source_bash.sh](https://github.com/rcmdnk/sentaku/blob/master/bin/ex_source_bash.sh)\n* [ex_source_zsh.sh](https://github.com/rcmdnk/sentaku/blob/master/bin/ex_source_zsh.sh)\n\nThey are example to use pre-defined list file (`$HOME/.my_input`),\nand select one from it.\n\nThe separator is `$'\\x07'` (BELL), therefore you can store even sentences in the list file (can be used as a snippet application).\n\nThese two are examples for Bash and Zsh, respectively.\n(only the shebang is different.)\n\n#### Example: Explorer\n\n* [ex_explorer.sh](https://github.com/rcmdnk/sentaku/blob/master/bin/ex_explorer.sh)\n\nIt starts from current directory, show all files/directories.\nIf you choose directory, the window goes to the chosen directory.\n\nAt sentaku window:\n\n* `s`: Show details (ls -l)\n* `d`: Delete selected file/directory\n* `l`: Open file with `less`\n* `e`: Open file with $EDITOR (or `vim`)\n* `Enter`/`Space`: Move the directly\n* `q`: Quit\n\n##### Tips\n\nThe original `_sf_select` function, which is executed when you push `Enter` or `Space`, is defined as:\n\n``` sh\n_sf_select () { # {{{\n  _s_break=1\n} # }}}\n```\n\nIf `_s_break` flag is 1, it breaks key operation and goes to `_sf_execute ()`.\nIf you want to skip `_sf_execute`, call `_sf_quit` instead of `_sf_select=`.\n\nIn this script, this function is redefined like:\n\n``` sh\n_sf_select () {\n  cd ${_s_inputs[$_s_current_n]}\n  ...\n}\n```\n\nIt does `cd` to currently selected directory (`${_s_inputs[$_s_current_n]}`),\n\n`_s_current_n` is currently selected number (same as the number in the left of the list.)\n`_s_inputs` is an array which is made from the input.\nTherefore, `${_s_inputs[$_s_current_n]}` is currently selected value.\n\nAnd it does not set `_s_break` flag,\ntherefore it stays in key operation (sentaku window).\n\nIf you want to break with any key, you can change `_s_break` flag in\ncorresponding function.\n\n\nAnother point: `_sf_l` is defined as:\n\n``` sh\n_sf_l () { # {{{\n  clear \u003e/dev/tty\n  less ${_s_inputs[$_s_current_n]} \u003e/dev/tty \u003c/dev/tty\n  _sf_quit\n} # }}}\n```\n\nIn this script, it opens selected file: `${_s_inputs[$_s_current_n]}`.\n\n#### Example: menu program\n\n* [ex_menu.sh](https://github.com/rcmdnk/sentaku/blob/master/bin/ex_menu.sh)\n\nFor the first window, you can choose:\n\n* Keyboard Input\n* ls\n* pwd\n* date\n* more\n\nIf you choose `Keyboard Input`, your input will be returned.\n`ls`, `pwd` and `date` return these commands results.\n\nIf you choose `more`, you will go to the second window\n\n* echo aaa\n* echo bbb\n* echo ccc\n* echo ddd\n\nEach command return such `aaa`.\n\nIf you put `q` here, you will be back to the first window.\n\n##### Tips\n\nIn this script, new sentaku instance is made in the function (at `more`).\n\nTo load sentaku in sentaku functions, do like\n\n    . sentaku -n -c\n\n`-c` option avoid to execute some functions which should not call\ntwice in the same process.\n\n#### Example: command game\n\n* [ex_slime.sh](https://github.com/rcmdnk/sentaku/blob/master/bin/ex_slime.sh)\n\nUsage:\n\n* ./ex_slime.sh # Japanese\n* ./ex_slime.sh -e # English\n\n\n* [Demo](http://asciinema.org/a/7340):\n\n[![slime](http://rcmdnk.github.io/images/post/20140124_slime.jpg)](http://asciinema.org/a/7340)\n\n#### Example: ddv (Diff Directories and open with Vim)\n\n* [ddv](https://github.com/rcmdnk/sentaku/blob/master/bin/ddv)\n\nUse like:\n\n    $ ddv dir1 dir2\n\n`ddv` makes a list of files which are in both directories, but have differences.\n\nUse `Enter`/`Space` to open these files with `vim -d`.\nThen, you can edit these files with vim diff mode.\n\nYou can remove a file from the sentaku window by `d`,\nonce you edited and file becomes fine or you think the file is not needed to be edited.\n\n* [Demo](http://asciinema.org/a/7373):\n\n[![ddv](http://rcmdnk.github.io/images/post/20140127_ddv.jpg)](http://asciinema.org/a/7373)\n\n#### Other examples from other repositories\n\n##### sd_cl\n\n[rcmdnk/sd_cl](https://github.com/rcmdnk/sd_cl)\n\nUseful functions to change directories for Bash/Zsh and GNU screen/tmux.\n\n##### trash\n\n[rcmdnk/trash](https://github.com/rcmdnk/trash)\n\nRemove Command using a trash box.\n\n##### multi_clipboard\n\n[rcmdnk/multi_clipboard](https://github.com/rcmdnk/multi_clipboard)\n\nClipboard manager for GNU screen.\n\n## References\n\n* [シェルスクリプトで対話的な選択を出来るようにするスクリプトを作った:sentaku](http://rcmdnk.github.io/blog/2014/01/24/computer-bash-zsh/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcmdnk%2Fsentaku","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frcmdnk%2Fsentaku","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcmdnk%2Fsentaku/lists"}