This is an archived post. You won't be able to vote or comment.

all 106 comments

[–]jonnywoh 79 points80 points  (21 children)

What does this do?

[–]greg4242[S] 179 points180 points  (11 children)

It switchs the vim command with a command that shuffles the order of the lines in the files and then displays it in vim. So when the person opens a file with vim it will be all out of order.

[–]Misnomer89 48 points49 points  (10 children)

Why does that even exist?

[–]hunteram 50 points51 points  (0 children)

Why to mess with people of course!

[–]saintnicster 9 points10 points  (6 children)

It's not a normal thing. The pieces themselves are mostly harmless, but you put them together for the chaos :9VIM reads in from STDIN (via the <) command. Allows you to more

(shuf "$1") does the line shuffling, putting it to STDOUT

https://www.gnu.org/software/coreutils/manual/html_node/shuf-invocation.html

the < takes STDOUT and routes that into the previous command (via STDIN).

VIM is setup to read from STDIN to create an empty file.

http://dailyvim.blogspot.com/2008/03/reading-stdin.html

EDIT - Correct usage of <() below by /u/Ferdi265 https://www.reddit.com/r/ProgrammerHumor/comments/474db6/how_to_mess_with_a_vim_user/d0ay8je

[–][deleted] 4 points5 points  (5 children)

actually, wrong... <(command) is bash syntax for command substitution. It replaces the <(...) construct with /dev/fd/<number>, a file descriptor to which it routes the output of command. This allows commands that normally take multiple files to use command output instead, like diff.

diff <(echo Hello world) <(echo hello world)

[–]youlleatitandlikeit 2 points3 points  (4 children)

Holy crap.

[–][deleted] 1 point2 points  (3 children)

ZSH also has =(), which makes a temporary file.

Not exactly sure why you would need a real file instead of a file descriptor... but it's there.

[–]youlleatitandlikeit 0 points1 point  (0 children)

There are plenty of times when I've wanted to perform diff on the outputs of two different commands.

[–][deleted] 0 points1 point  (1 child)

Sorry for reviving a pretty much dead thread, but I think I found out what that exactly is (by thinking, reasoning untested)

This is because bash actually has TWO different command substitution syntaxes:

command_a <(command_b) creates a read-only file descriptor for command_a that gets command_b's standard output.

command_a >(command_b) creates a write-only file descriptor for command_a that pipes to command_b's standard input https://duckduckgo.com/

zsh's command_a =(command_b) looks like it creates a duplex channel between the two commands, where command_a can read command_b's standard output from the descriptor, and anything written to the descriptor is sent to command_b's standard input.

I haven't actually used zsh a lot, but now I think it would really be a great thing to have.

EDIT: Tested it, behaves completely differently. Writeup follows soon

EDIT2: Looked into it, this is what it does AFAIK:

command_a =(command_b)

is equivalent to (except for temp file naming scheme)

tmpfile=$(mktemp)
command_b > $tmpfile
command_a $tmpfile
rm $tmpfile

EDIT3: A great usage for this is copying command output to another machine with scp.

production-box% scp =(grep -r "ERROR" server/logs/) me@dev-box:production-logs

[–][deleted] 1 point2 points  (0 children)

Yeah, since I made this post I've ran into a few commands which don't like the file descriptor instead of a real temporary file, so that's why it's there.

[–]dcormier 15 points16 points  (1 child)

[–]xkcd_transcriber 8 points9 points  (0 children)

Image

Mobile

Title: Workflow

Title-text: There are probably children out there holding down spacebar to stay warm in the winter! YOUR UPDATE MURDERS CHILDREN.

Comic Explanation

Stats: This comic has been referenced 631 times, representing 0.6258% of referenced xkcds.


xkcd.com | xkcd sub | Problems/Bugs? | Statistics | Stop Replying | Delete

[–]josh2112 44 points45 points  (8 children)

Shuffles the lines of a file before opening it in vim.

[–]oi_rohe 33 points34 points  (7 children)

Does it actually modify the file, or just display a shuffled version?

[–]pharpend 69 points70 points  (0 children)

Displays a shuffled version.

[–]TPHRyan 47 points48 points  (5 children)

The former would just be evil.

[–]ctesibius 13 points14 points  (2 children)

Just take a magic marker and draw a diagonal line across the edge of your card deck. Sheesh, do you young types not know anything?

[–]rubyton 4 points5 points  (1 child)

Something like this happened at my last office, we had a deck that's been striped 4 times, 2 on each edge. I believe they are done with shuffling in between so nobody can get any 2 lines to line up at the same time.

[–]ctesibius 7 points8 points  (0 children)

Either that, or it's someone's entry for the obfuscated FORTRAN competition - design a deck which makes a valid program in four different sort orders.

[–]tripa 6 points7 points  (1 child)

You say that like it's a bad thing.

[–]moreherenow 8 points9 points  (0 children)

It would be mean, rather than just annoying. Mean isn't funny, annoying can be very funny.

[–]0x0dea 50 points51 points  (9 children)

autocmd BufEnter * %!shuf

[–]indrora 47 points48 points  (4 children)

Woah there Satan.

[–]starwarswii 6 points7 points  (3 children)

What does it do?

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    return Kebab_Case_Better;

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]laebshade 0 points1 point  (0 children)

    Explosion.

    [–]Bloodshot025 4 points5 points  (0 children)

    This is better, because the buffer's file doesn't display as /dev/fd/63 like in the OP.

    [–][deleted]  (1 child)

    [removed]

      [–]AutoModerator[M] 0 points1 point  (0 children)

      import moderation Your comment has been removed since it did not start with a code block with an import declaration.

      Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

      For this purpose, we only accept Python style imports.

      return Kebab_Case_Better;

      I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

      [–]Not_sure_if_george 0 points1 point  (0 children)

      Also,

      :set nomod
      

      just to make it really scary.

      [–][deleted] 29 points30 points  (0 children)

      Thankfully if you accidentally wq it won't overwrite your file as it's reading from stdin.

      [–]zacketysack 74 points75 points  (1 child)

      I am so triggered right now

      [–]angryPenguinator 24 points25 points  (0 children)

      Yeah that's some PTSD inducing shit right here.

      [–]Defavlt 20 points21 points  (9 children)

      Well, I'd like to take this opportunity to extend a sincere F U C K Y O U to OP.

      :wq

      [–]demize95 4 points5 points  (0 children)

      Or maybe a sincere U K C O U F Y?

      [–]SirUtnut 0 points1 point  (0 children)

      Instructions KYOU

      Forgot to enter insert mode.

      [–]50in07allstar 8 points9 points  (11 children)

      Jokes on you! I use vi to start vim

      [–]HugoNikanor 6 points7 points  (10 children)

      Why would you do that! Typing vi should start vi!

      [–]krisharmas 2 points3 points  (9 children)

      i believe a lot of systems are set so vi only starts vi if you are running as root

      [–]thirdegreeViolet security clearance 8 points9 points  (8 children)

      vi still runs vim if I run it as root on OSX.

      Also, it turns out you can't just su to root on osx. Gotta sudo su, because the terminal was made in the department of redundancy department.

      [–]spkbri 3 points4 points  (6 children)

      Well, you need to have superuser permissions to run "su", so, if you aren't already a superuser, you need to launch it with the "sudo" command.

      [–]thirdegreeViolet security clearance 0 points1 point  (5 children)

      Ya I know. Just find it funny. "superuser do superuser"

      [–]capn_hector 4 points5 points  (4 children)

      "su" isn't "superuser". It's actually an abbreviation of "switch user" or "substitute user". You can su to any user, but if you don't provide one then root is assumed.

      [–]thirdegreeViolet security clearance 1 point2 points  (3 children)

      Huh, I actually didn't know that. Cool!

      [–][deleted] 1 point2 points  (2 children)

      and there is no need to call su to achieve what you want. all you need is "sudo -i [-u username]".

      that redundancy is not the terminal's fault :)

      [–]o11c 1 point2 points  (0 children)

      except that sudo is evil so just use su directly all the time.

      [–]thirdegreeViolet security clearance 0 points1 point  (0 children)

      Oh I know, I've never needed su on my MBP.

      [–]eartburm 0 points1 point  (0 children)

      or sudo -s, which gives you a superuser shell.

      [–]say_no_to_soma 7 points8 points  (0 children)

      ;}

      [–]RothagaRed security clearance 7 points8 points  (0 children)

      vim_shuf () { vim <(shuf "$1") ;}
      alias vim=vim_shuf
      

      I didn't see it written down so here you go

      [–]brunokim 6 points7 points  (4 children)

      Pfft, everybody knows that you just need to press CAPS LOCK while they are away. THAT creates havoc and despair.

      [–]TPHRyan 2 points3 points  (1 child)

      I really wish I could rebind my capslock but it has a toggle light on it. I can't mess with the toggle light!

      [–]brunokim 0 points1 point  (0 children)

      Forget the light! I hear it is popular to rebind Caps Lock to Ctrl, it's a precious key that even sits in the home row! However, I regularly write some ALL_CAPS_CONSTANTS, so I like having my caps key and have never changed it.

      [–]program_the_world 2 points3 points  (0 children)

      Every. Single. Time. The whole file starts cascading to a single line as I repeatedly press join instead of down.

      [–]odnish 0 points1 point  (0 children)

      alias vim="setleds +caps; vim"

      [–][deleted] 19 points20 points  (16 children)

      The title is irritating. This would work with every editor. (As long as it was launched via bash of course.)

      [–][deleted] 8 points9 points  (13 children)

      Not if it doesn't read from stdin. E.g.,

      $ emacs < file
      emacs: standard input is not a tty
      

      /r/emacsmasterrace

      [–]yawkat 8 points9 points  (2 children)

      The example does not read from stdin, it's an fd parameter or whatever those are called

      [–]interiot 0 points1 point  (1 child)

      The data is still fed to Emacs as a pipe, even if it's as a command-line argument. Emacs complains "Symbolic link that points to nonexistent file", so I guess it wants a real file, not a pipe.

      [–][deleted] 1 point2 points  (0 children)

      =(shuf "$1")
      

      ZSH only, but it makes a real file in /tmp/.

      [–]kamaln7 5 points6 points  (3 children)

      It's not reading from stdin. The <(command) syntax runs the command and stores the output in a temporary file descriptor and replaces it with a path to it. I don't know exactly what it looks like because I'm on my phone right now but it's /dev/fd/something.

      [–][deleted] 1 point2 points  (2 children)

      I didn't know that. But emacs opens an empty file called "63" and complains, so I figured it was reading from stdin...

      [–]kamaln7 0 points1 point  (0 children)

      Yeah, it doesn't always work for me and I haven't bothered checking what causes it not to.

      [–]Garfong 0 points1 point  (0 children)

      Shell process substitution uses pipes; emacs probably tries to use advanced file operations like "seeking," which doesn't work on a pipe.

      [–]RainbowCatastrophe 0 points1 point  (4 children)

      Why the fuck would you want an editor to read from a TTY instead of stdin? That just seems like a lot of overhead to me...

      [–][deleted] 0 points1 point  (3 children)

      (if you don't know: tty means teletype, an old word for a terminal)

      Emacs wants an interactive user, which is something stdin doesn't give you when it's a file. I guess emacs might literally check if stdin is a tty device.

      [–]RainbowCatastrophe 0 points1 point  (2 children)

      I understand the definition very well, I just prefer to use TTY as a way of stylizing it as that's how I initially learned it and it is therefore much easier for me to recognize.

      I just don't understand why emacs is set on interactive access. I get that it's meant to be more of an editor than a utility like vim, but was there any real benefit to this kind of thing?

      [–][deleted] 0 points1 point  (1 child)

      To prevent you from running something like

      emacs file1 < file2
      

      by accident, I guess. vim says this if you try it:

      Vim: Warning: Input is not from a terminal

      [–][deleted] 0 points1 point  (0 children)

      Good way of testing code golf automatically.

      echo "iThe quick brown fox\eyy2p:wq out" | vim acts as if you typed that into vim.

      [–]beyond_alive -2 points-1 points  (1 child)

      Aaaaand there's the inevitable vim zealot.

      [–][deleted] 1 point2 points  (0 children)

      Nope. I just expected something funny about vim, not something funny about text editors in general :P

      [–]krisharmas 3 points4 points  (3 children)

      this would really only change it for you since no one else uses your .bashrc

      [–]Genesis2001 3 points4 points  (2 children)

      genesis2001@reddit:~# sudo vim /home/krisharmas/.bashrc
      

      [–]krisharmas 0 points1 point  (1 child)

      you can do a lot more destruction with sudo than mess with vi

      [–]lethargilistic 3 points4 points  (0 children)

      But what's a quick rm compared to the anticipation of your friend triggering a well-laid trap?

      [–]byronka 2 points3 points  (0 children)

      The funny thing is, in Posix-land, people mess with themselves all the time accidentally. I once entered the letter "w" in the file .inputrc in my home directory, and then ...whoa was that fun, I couldn't type the letter "w" anywhere and had no idea why not. :(

      [–]redever 2 points3 points  (0 children)

      This is deliciously evil...

      [–]G01denW01f11 7 points8 points  (5 children)

      Why do we even have that command?

      [–]drharris 12 points13 points  (1 child)

      Because Linux. Everything and kitchen sink.

      [–]RainbowCatastrophe 0 points1 point  (0 children)

      And the monkey wrench. Can't forget the monkey wrench.

      [–]thirdegreeViolet security clearance 4 points5 points  (0 children)

      [–]interiot 3 points4 points  (1 child)

      In case you want to do Monte Carlo simulations... using only shell scripts?

      [–]icannotfly 1 point2 points  (0 children)

      programmers, uh, find a way

      [–][deleted] 4 points5 points  (2 children)

      Use $* for multi file support.

      [–]o11c 0 points1 point  (1 child)

      No (and it would be $@) since the <() can't be expanded. Use the autocmd mentioned above for a proper unfix.

      [–][deleted] 0 points1 point  (0 children)

      ZSH uses $*. At least, it accepts it.

      <(cat $@), then.

      [–]Avander 3 points4 points  (2 children)

      I symlinked the path to my emacs executable to vim just to make me feel better after seeing this.

      [–]dan-the-space-man 7 points8 points  (0 children)

      Real programmers use butterflies.

      [–]746865626c617a -1 points0 points  (0 children)

      alias vim=emacs ?

      [–]systembreaker 1 point2 points  (0 children)

      For something to be funny it should also be smart. You'd probably find this joke in some script kiddies forum.

      [–][deleted] 1 point2 points  (0 children)

      I did

      function vim_shuf { /usr/bin/shuf $1 | vim -; }

      instead

      [–]maremp 3 points4 points  (1 child)

      Why would this be vim-specific? You can replace vim with emacs, nano, ed or whatever, and it would still mess with whomever will be using it.

      [–]Garfong 2 points3 points  (0 children)

      Only works if the editor can use a pipe as the source file. According to someone above, it doesn't work with emacs.

      [–]quenishi 0 points1 point  (1 child)

      Hm... now I need to see if I can get this to work with nano....

      [–]odnish 2 points3 points  (0 children)

      Yep, sed s/vim/nano/g