a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment by empty
empty  ·  3185 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).




deepflows  ·  3185 days ago  ·  link  ·  

Thank you. That was a great explanation! It made me understand better what's going on in principle. You are right, Hubski's formatting messed up the example. Unfortunately, for some reason the verbatim option did not work, it just printed the character in front of my text but still interpreted the * and | as syntax.

Anyways, I take away from this that regular expressions are something I may definitely want to look into in the future (preferably using a tutorial "from the ground up"), but don't really need to worry about for the moment.

empty  ·  3185 days ago  ·  link  ·  

Yes, I agree. The first step is to understand what needs to be done. Anyone who tells you that you need to learn the most obscure and unreadable perl one-liners to be a True Linux User is full of shit. Those one-liners make no sense unless you are already familiar with the sorts of editing tasks that you might need to do in the first place.

user-inactivated  ·  3185 days ago  ·  link  ·  

    Anyone who tells you that you need to learn the most obscure and unreadable perl one-liners to be a True Linux User is full of shit.

Does anyone ever say that? When I hand out a line noisey incantation without much explanation it's usually something that would require a lot of explanation and in response to someone who sounds like they just want their problem to go away.

user-inactivated  ·  3185 days ago  ·  link  ·  

Certainly used to, back when I paid attention to Linux news. It was a reasonably elitist community for a while. Helpful, but, ya know.

user-inactivated  ·  3185 days ago  ·  link  ·  

I've been using linux since 1997. It is an elitist community and always has been, but in my experience it'll tell you to RTFM if your question is answered in TFM, but it will give you good advice if it decides to give you advice at all. "Start out by learning to perl golf" isn't good advice.

caelum19  ·  3184 days ago  ·  link  ·  

Brilliant explanation. deepflows and anyone else into learning/using regex, I find Regex101 a very helpful tool.

empty  ·  3184 days ago  ·  link  ·  

Oh wow, what a great site. I've seen similar ones in the past but I like the UI way better.

Reef3  ·  3184 days ago  ·  link  ·  

Just wanted to say, I use Ubuntu with Gnome3 on my laptop and I love it! I really like how Gnome have re-imagined the desktop metaphor and I feel very productive and everything stays out fo my way until I need it, and then it's all there and digestible with the push of a button or nudge of the mouse. My only gripe is that it uses a love of vertical screen space which isn't ideal on a tiny 11in screen.

user-inactivated  ·  3183 days ago  ·  link  ·  

I hated Gnome 3 at first, it definitely had some issues on launch. But the Gnome team really have done an amazing job. It's by far my favorite DE I've ever used. I'm an RPM guy so I've been using Fedora + Gnome 3.

empty  ·  3184 days ago  ·  link  ·  

In the past, I've preferred to use tiled window managers such as i3 or xmonad on devices with smaller screens. They offer more keyboard shortcuts for manipulating windows and take up less vertical space with things like docks or menus.

Reef3  ·  3183 days ago  ·  link  ·  

I was actually looking into Awesome and i3 the other day. I was thinking about trying one of them out on top of gnome to get the feel for it. Snapping widows to the edges of the screen to easily see two windows side by side is already something I rely on, so I could see the benefits of a tiling window manager.

aidrocsid  ·  3185 days ago  ·  link  ·  

Personally, I'm a Xubuntu fan myself. XFCE is so much cleaner.