Skip to content
Myr

Expose state information via environment variables to child processes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Close #3582

authored by Junegunn Choi · committed by Junegunn Choi · parent 1a9ea6f · Browse files · 3 files+85 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+85 added−10 removed

  • other:+85 added−10 removed

3 files+85 added−10 removed

modified:man/man1/fzf.1+33 added-2 removed
590 unmodified lines
591.br592* \fB{n}\fR is replaced to the zero-based ordinal index of the current item.593 Use \fB{+n}\fR if you want all index numbers when multiple lines are selected.594.br595* \fB{fzf:action}\fR is replaced to to the name of the last action performed596* \fB{fzf:prompt}\fR is replaced to to the prompt string595596Note that you can escape a placeholder pattern by prepending a backslash.597598Preview window will be updated even when there is no match for the current
299 unmodified lines
898.br899.BR .. " All the fields"900.br901902.SH ENVIRONMENT VARIABLES EXPORTED TO CHILD PROCESSES903904fzf exports the following environment variables to its child processes.905906.BR FZF_LINES " Number of lines fzf takes up excluding padding and margin"907.br908.BR FZF_COLUMNS " Number of columns fzf takes up excluding padding and margin"909.br910.BR FZF_TOTAL_COUNT " Total number of items"911.br912.BR FZF_MATCH_COUNT " Number of matched items"913.br914.BR FZF_SELECT_COUNT " Number of selected items"915.br916.BR FZF_QUERY " Current query string"917.br918.BR FZF_PROMPT " Prompt string"919.br920.BR FZF_ACTION " The name of the last action performed"921.br922.BR FZF_PORT " Port number when --listen option is used"923.br924925The following variables are additionally exported to the preview commands.926927.BR FZF_PREVIEW_TOP " Top position of the preview window"928.br929.BR FZF_PREVIEW_LEFT " Left position of the preview window"930.br931.BR FZF_PREVIEW_LINES " Number of lines in the preview window"932.br933.BR FZF_PREVIEW_COLUMNS " Number of columns in the preview window"934935.SH EXTENDED SEARCH MODE936937Unless specified otherwise, fzf will start in "extended-search mode". In this938mode, you can specify multiple patterns delimited by spaces, such as: \fB'wild
514 unmodified lines
modified:src/terminal.go+25 added-8 removed
289 unmodified lines
290 executing *util.AtomicBool291 termSize tui.TermSize292 lastAction actionType293 lastFocus int32294 areaLines int295 areaColumns int296}297298type selectedItem struct {299 at time.Time
152 unmodified lines
452 actShowHeader453 actHideHeader454)455456func (a actionType) Name() string {457 name := ""458 for i, r := range a.String()[3:] {459 if i > 0 && r >= 'A' && r <= 'Z' {460 name += "-"461 }462 name += string(r)463 }464 return strings.ToLower(name)465}466467func processExecution(action actionType) bool {468 switch action {469 case actTransform,470 actTransformBorderLabel,
366 unmodified lines
837 env := os.Environ()838 if t.listenPort != nil {839 env = append(env, fmt.Sprintf("FZF_PORT=%d", *t.listenPort))840 }841 env = append(env, "FZF_QUERY="+string(t.input))842 env = append(env, "FZF_ACTION="+t.lastAction.Name())843 env = append(env, "FZF_PROMPT="+string(t.promptString))844 env = append(env, fmt.Sprintf("FZF_TOTAL_COUNT=%d", t.count))845 env = append(env, fmt.Sprintf("FZF_MATCH_COUNT=%d", t.merger.Length()))846 env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected)))847 env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines))848 env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))849 return env850}851852func borderLines(shape tui.BorderShape) int {
458 unmodified lines
1311 }1312 width -= paddingInt[1] + paddingInt[3]1313 height -= paddingInt[0] + paddingInt[2]13141315 t.areaLines = height1316 t.areaColumns = width13171318 // Set up preview window1319 noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)1320 if forcePreview || t.needPreviewWindow() {1321 var resizePreviewWindows func(previewOpts *previewOpts)
1244 unmodified lines
2566 return quoteEntry(item.AsString(params.stripAnsi))2567 }2568 }2569 case match == "{fzf:action}":2546 name := ""2547 for i, r := range params.lastAction.String()[3:] {2548 if i > 0 && r >= 'A' && r <= 'Z' {2549 name += "-"2550 }2551 name += string(r)2552 }2553 return strings.ToLower(name)2570 return params.lastAction.Name()2571 case match == "{fzf:prompt}":2572 return quoteEntry(params.prompt)2573 default:2574 // token type and also failover (below)
1610 unmodified lines
modified:CHANGELOG.md+27 added
2 unmodified lines
340.46.0 (WIP)5------6- Added `result` event that is triggered when the filtering for the current query is complete and the result list is ready.7- fzf now exports the following environment variables to the child processes8 | Variable | Description |9 | --- | --- |10 | `FZF_LINES` | Number of lines fzf takes up excluding padding and margin |11 | `FZF_COLUMNS` | Number of columns fzf takes up excluding padding and margin |12 | `FZF_TOTAL_COUNT` | Total number of items |13 | `FZF_MATCH_COUNT` | Number of matched items |14 | `FZF_SELECT_COUNT` | Number of selected items |15 | `FZF_QUERY` | Current query string |16 | `FZF_PROMPT` | Prompt string |17 | `FZF_ACTION` | The name of the last action performed |18 - This allows you to write sophisticated transformations like so19 ```sh20 # Dynamically resize preview window21 seq 10000 | fzf --bind 'result:transform:22 # 1 line for info, another for prompt, and 2 more lines for preview window border23 lines=$(( FZF_LINES - FZF_MATCH_COUNT - 4 ))24 if [[ $FZF_MATCH_COUNT -eq 0 ]]; then25 echo "change-preview-window:hidden"26 elif [[ $lines -gt 3 ]]; then27 echo "change-preview-window:$lines"28 elif [[ $FZF_PREVIEW_LINES -ne 3 ]]; then29 echo "change-preview-window:3"30 fi31 ' --preview 'seq {} 10000' --preview-window up32 ```33 - And we're phasing out `{fzf:prompt}` and `{fzf:action}`34- Bug fixes35360.45.037------
1814 unmodified lines