Skip to content

Help with pipe and vim

Hi. Could someone please help me with this pipe thingy? I want to pipe files' content into dmenu, so I can choose one of the files and then open it with vim. Everything is working perfectly fine except for one thing: Vim opens the file as a new file.

​

#!/bin/bash
vim $(cat ~/.config/config/files | dmenu -l 30 |awk '{print $2}')

​

files

Bash ~/.bashrc
Bspwm ~/.config/bspwm/bspwmrc
Polybar ~/.config/polybar/config
Sxhkd ~/.config/sxhkd/sxhkdrc
Dunst ~/.config/dunst/dunstrc
Vim ~/.vimrc
Xresources ~/.Xresources
Neofetch ~/.config/neofetch/config.conf
Sxiv ~/.config/sxiv/exec/key-handler

Edited 16 May 2019. We only hold this version.

10 points6 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
10 · 100% up
Kind
Text
ID
bpgvnv

Author

2
posts
57
comments
0
media
View profile

7 comments

Add set -x before your one-liner to see what is happening.

+/bin/zsh:53> cat files
+/bin/zsh:53> dmenu -l 30
+/bin/zsh:53> awk '{print $2}'
+/bin/zsh:53> vim '~/.vimrc'

vim is opening '~/.vimrc' and not /home/$USER/.vimrc. The tilde '~' is not expanded.

You can use awk to substitute the tilde with your $HOME variable:

vim $(cat files | dmenu -l 30 |awk '{sub("~", "'$HOME'"); print $2}')
8 points
unknown author

Deleted before we saved it.

2 points

If you put the full path for each file into that "files" it works like /home/user/.bashrc
Although it should work with $HOME but can't get that parameter expansion to work with awk right now.

6 points
unknown author

Deleted before we saved it.

2 points

~ as a shortcut for your home directory is a shell expansion, so without passing the filename through your shell then vim is looking for a directory literally named ~.

5 points
unknown author

Deleted before we saved it.

1 points
unknown author

Deleted before we saved it.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.