• 1 Post
  • 19 Comments
Joined 1 year ago
cake
Cake day: February 17th, 2024

help-circle


  • I checked the locale and it is correct. I’m on Arch, and I just installed neovim to compare the cursor and typing behaviors, and in neovim it acts as expected when I type the ~.

    I did notice that in vim, I now have a blinking block cursor in insert mode as well as in visual mode, while in neovim, it’s a block cursor in visual mode and a vertical bar cursor in insert mode. This was the normal behavior in vim prior to whatever the heck I did.

    Edit: grammar




  • Nicely done! Happy I could help.

    There’s a million ways to do it and none are “right”, so I wouldn’t call yours sloppy at all. I’m still learning and have lots of slop in my own expressions. 🤣

    I’ll turn around and ask you a question if you don’t mind. That last bit you used, I kind of understand what it’s doing, but not fully. I’m getting that it’s excluding https, but if you could explain the syntax I’d really appreciate it!

    This is the bit:

    /https/ ! s|%20|-|g

    Edit: removed a redundancy


  • Feel free to ping me if you want some help! I’d say I’m intermediate with regex, and I’m happy to help where I can.

    Regarding the other file, you could pretty easily modify the command I gave you to adapt to the example you gave. There’s two approaches you could take.

    This is focused on the first regex in the command. The second should work unmodified on the other files if they follow the same pattern.

    Here’s the original chunk:

    s|]\(#.+\)|\L&|

    In the new example given, the # is preceded by readme.md. The easy modification is just to insert readme\.md before the # in the expression, adding the \ before the . to escape the metacharacter and match the actual period character, like so:

    s|]\(readme\.md#.+\)|\L&|

    However, if you have other files that have similar, but different patterns, like (faq.md#%20link%20text), and so on, you can make the expression more universal by using the .* metacharacter sequence. This is similar to the .+ metacharacter sequence, with one difference. The + indicates one or more times, while the * indicates zero or more times. So by using .* before the # you can likely use this on all the files if they follow the two pattern examples you gave.

    If that will work, this would be the expression:

    s|]\(.*#.+\)|\L&|

    What this expression does is:

    Find find a closing bracket followed by a opening parentheses followed by any sequence of characters (including no characters at all) until finding a pound/hash symbol then finding one or more characters until finding a closing parentheses, and convert that entire matched string to lowercase.

    And with that modified expression, this would be the full command:

    sed -ri 's|]\(#.+\)|\L&|; s|%20|-|g' /path/to/somefile
    

    Edit: grammar

    Edit 2: added the full modified command.


  • Okay, here’s the command and a breakdown. I broke down every part of the command, not because I think you are dumb, but because reading these can be complicated and confusing. Additionally, detailed breakdowns like these have helped me in the past.

    The command:

    sed -ri 's|]\(#.+\)|\L&|; s|%20|-|g' /path/to/somefile
    

    The breakdown:

    sed - calls sed

    -r - allows for the use of extended regular expressions

    -i - edit the file given as an argument at the end of the command (note, the i flag must follow the r flag, or the extended regular expressions will not be evaluated)

    Now the regex piece by piece. This command has two substitution regex to break down the goals into managable chunks.

    Expression one is to convert the markdown links to lowercase. That expression is:

    's|]\(#.+\)|\L&|;

    The goal of this expression is to find markdown links, and to ignore https links. In your post you indicate the markdown links all start with a # symbol, so we don’t have to explicitly ignore the https as much as we just have to match all links starting with #. Here’s the breakdown:

    ' - begins the entire expression set. If you had to match the ' character in your expression you would begin the expression set with " instead of '.

    s| - invoking find and replace (substitution). Note, Im using the | as a separator instead of the / for easier readability. In sed, you can use just about any separator you want in your syntax

    ]\(# - This is how we find the link we want to work on. In markdown, every link is preceded by ]( to indicate a closing of the link text and the opening of the actual url. In the expression, the ( is preceded by a \ because it is a special regex character. So \( tells sed to find an actual closing parentheses character. Finally the # will be the first character of the markdown links we want to convert to lowercase, as indicated by your example. The inclusion of the # insures no https links will be caught up in the processing.

    .+ - this bit has two parts, . and +. These are two special regex characters. the . tells sed to find any character at all and the + tells it to find the preceding character any number of times. In the case of .+, it’s telling sed to find any character and this pattern can repeat any number of times. You might think this will eat ALL of the text in the document and make it all lowercase, but it will not because of the next part of the regex.

    \) - this tells sed to find a closing parentheses. Like the opening parenthese, it is a special regex character and needs to be escaped with the backslash to tell sed to find an actual closing parentheses character. This is what stops the command from converting the entire document to lowercase, because when you combine the previous bit with this bit like so .+\), you’re telling sed to find any character UNTIL you find a closing parentheses.

    | - This tells sed we’re done looking for text to match. The next bits are about how to modify/replace that text

    \L - This tells sed to convert the given text to all lowercase

    & - Tells sed to convert the entire pattern matched to lowercase.

    ; - this tells sed that this is the end of the first expression, and that more are coming.

    So all together, what this first expression does is: Find a closing bracket followed by an opening parentheses followed by a pound/hash symbol followed by any number of any characters until finding a closing parentheses. Then convert that entire chunk of text to lowercase. Because symbols don’t have case you can just convert the entire matched pattern to lowercase. If there were specific parts that had to be kept case sensitive, then you’d have to match and modify more precisely.

    The next expression is pretty easy, UNLESS any of your https links also include the string %20:

    If no https links contain the %20 string, then this will do the trick:

    s|%20|-|g'

    s| - again opens the expression telling sed wer’re looking to substitute/modify text

    %20 - tells sed to find exactly the character sequence %20

    | - ends the pattern matching portion of the expression

    - - tells sed to replace the matched pattern with the exact character -

    | - tells sed that’s the end of the modification instructions

    g - tells sed to do this globally throughout the document. In other words, to find all occurrances of the string %20 and replace them with the string -

    ' - tells sed that is the end of the expression(s) to be evaluated.

    So all together, what this expression does is: Within the given document, find every occurrence of a percent symbol followed by the number two followed by the number zero and replace them with the dash character.

    /path/to/somefile - tells sed what file to work on.

    Part of using regex is understanding the contents of your own text, and with the information and examples given, this should work. However, if the markdown links have different formatting patterns, or as mentioned any of the https links have the %20 string in them, or other text in the document might falsely match, then you’d have to provide more information to get a more nuanced regex to match.









  • harsh3466@lemmy.mltoNix / NixOS@programming.devNotes on Nix
    link
    fedilink
    English
    arrow-up
    0
    ·
    10 days ago

    I just took a run at nixos the other day, and I hit a wall.

    I installed NixOS just fine, but when it came to looking for direction/documentation/tutorials to begin learning how to use and write my config, I just got more and more confused.

    If anyone can suggest a good tutorial series, be it video or written, to get up to speed on nix language and config, I’d be grateful.

    I’m a faily experienced Linux user, no expert, but comfortable at the command line, comfortable with bash scripting, comfortable managing my server. I can usually dive into something like nix and get a finger-hold on understanding, but I spent hours trying to find some clear tutorial and I just ended up more confused.



  • zoxide. It’s a fabulous cd replacement. It builds a database as you navigate your filesystem. Once you’ve navigated to a directory, instead of having to type cd /super/long/directory/path, you can type zoxide path and it’ll take you right to /super/long/directory/path.

    I have it aliased to zd. I love it and install it on every system

    You can do things like using a partial directory name and it’ll jump you to the closest match in the database. So zoxide pa would take you to /super/long/directory/path.

    And you can do partial paths. Say you’ve got two directories named data in your filesystem.

    One at /super/long/directory/path1/data

    And the other at /super/long/directory/path2/data

    You can do zoxide path2 data and you’ll go to /super/long/directory/path2/data