a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment
empty  ·  3388 days ago  ·  link  ·    ·  parent  ·  post: So... switching to Linux.

IMO the best out-of-the-box linux setup is Ubuntu with Gnome 3. It has the GUI config tools you're looking for (or at least, it has more than other distros I've tried).

As for (2), it works like this: Configuration in linux is done primarily through human-readable text files. The same goes for how processes communicate with each other. One program will spit out a bunch of text, the next program will eat that text and spit out more text, etc. A human centipede of small programs is the unix way.

And yes, if you really want to be a power user, you will probably need to learn regular expressions, which are a mini-programming language used for manipulating text. That is what the `sed` command is doing in your example. It's like find-and-replace on steroids. Once you understand what each part means, it won't look so scary.

But you don't need to do that. The command is just an automated way of going through a big config file by hand and manually changing a whole bunch of entries.

First, know that `sed` means "stream editor". Here's your regex:

    s/^[^ ][^V].id=\([0-9]\)./\1/p

Let's break it down into parts. First, the top-level structure of a sed command:

    s/foo/bar/baz

The s means we're going to do a substitution. The foo is what we're searching for, and the bar is what we'll replace matches with. The baz on the end are options that affect other stuff, like case insensitivity or whether or not to do more than one substitution per line.

In your command, the foo part is

    ^[^ ][^V].id=\([0-9]\).

Let's break it down.

    ^

This first carat will match the beginning of a line.

    [^ ]
Brackets mean a character class. For example, [abc] would match one occurrence of any of those letters. If my regex was [abc]d, then it would match the strings "ad", "bd", "cd". But if the list of characters starts with ^, then the class is inverted. So [^ ] means "match one character which is anything but a space.".

    [^V]

Same as before, but now we're matching anything but a V.

    .id=

The . means "any character", and then id= is just taken literally.

    \([0-9]\)

This is the interesting part of the pattern. The \( and \) introduce a "capture group". Any substring matched in a capture group will be available in our replace pattern. This is very powerful for doing complex search-and-replace stuff. Inside the capture group we have another character class. This time it's 0-9, which means any character from 0 up to 9. So basically just the digits 0123456789.

    .

And then another arbitrary character.

Before we move on to the third section of the sed command, let's think about what our search pattern will match.

    Vaid=31
    Vbid=1p
    V.id=3.

I suspect that the author of your regex made a mistake, and wanted actual periods like in the third example.

Let's look at the last two sections.

    /\1/p

The replacement pattern is just \1. \1 refers to the capture group we talked about earlier, so this \1 means "take that number you found before, and replace the whole match with just that number".

    p

This is some option that has to do with printing the inputs or something, but I don't remember off the top of my head because I don't use it that much.

So, in total, the command means "Find stuff that looks like ' V.id=(some number).' and replace it with just that number." This sed command is consuming input from `xinput list`, so it's probably intended to grab the numeric ids of a bunch of devices from the plaintext output of `xinput list`.

Also I just realized that hubski's formatting probably obliterated some of the regex you posted. The markup tips mention a "verbatim" option.

Here's the output of `xinput list` on my machine:

  ⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
  ⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
  ⎜   ↳ xquartz virtual pointer                 	id=6	[slave  pointer  (2)]
  ⎜   ↳ pen                                     	id=8	[slave  pointer  (2)]
  ⎜   ↳ cursor                                  	id=9	[slave  pointer  (2)]
  ⎜   ↳ eraser                                  	id=10	[slave  pointer  (2)]
  ⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
      ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
      ↳ xquartz virtual keyboard                	id=7	[slave  keyboard (3)]
So yeah. We can see that there's a bunch of Virtual stuff with that uppercase V, and then later in the line, there's id=(some single digit).