junegunn / junegunn/fzf

Make `--with-nth` strip the last delimiter

Open
#4,274 3 comments 1 reaction 1 assignee Claimed by @junegunn View on GitHub
discussion enhancement
Dominant language
Go
Stars
83k
Forks
2.9k
Avg merge
17h 8m
Merged PRs (30d)
10

Description

https://github.com/junegunn/fzf/issues/1323#issuecomment-2676390684

Currently, `--with-nth` keeps the last trailing delimiter.

```sh
echo foo,bar,baz | fzf --delimiter , --with-nth 2,1
# bar,foo,
```

This behavior is usually not desirable, but now you can work around it by using a template.

> [!NOTE]
> When you use a template, the trailing delimiter is stripped from each expression, giving you more control over the output.

```sh
echo foo,bar,baz | fzf --delimiter , --with-nth '{2},{1}'
# bar,foo
```

Should we strip the last trailing delimiter by default? It means breaking backward compatibility, but you can replicate the old behavior using templates.

```sh
# Please keep the last comma!
echo foo,bar,baz | fzf --delimiter , --with-nth '{2},{1},'
# bar,foo,
```

However, when rearranging markdown table columns, keeping the last delimiter is desirable because it contains whitespaces for alignment, and you can't replicate the previous behavior using templates.

```sh
fzf --reverse --delimiter ' *\| *' --with-nth ..3 << 'EOF'
| Package Manager | Linux Distribution | Command |
| --------------- | ----------------------- | ---------------------------------- |
| APK | Alpine Linux | `sudo apk add fzf` |
| APT | Debian 9+/Ubuntu 19.10+ | `sudo apt install fzf` |
EOF

# This doesn't work
fzf --reverse --delimiter ' *\| *' --with-nth '{..3} |' << 'EOF'
| Package Manager | Linux Distribution | Command |
| --------------- | ----------------------- | ---------------------------------- |
| APK | Alpine Linux | `sudo apk add fzf` |
| APT | Debian 9+/Ubuntu 19.10+ | `sudo apt install fzf` |
EOF

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.