serhii.net

In the middle of the desert you can say anything you want

20 Oct 2020

Day 659

zsh alias pwd | xc

alias pwx='pwd | xc'

I really need to gather them all in one place and make ~/.zshrc cleaner and neater.

bash / python / whatever todo small things


```
cc() python3 -c "from math import *; from statistics import *; print($*);"
alias cc='noglob cc'
```

Added `statistics` to it, now I can do things like `cc mean([2, 4, 9])`. (As a bonus `stdev()` etc., [full list](https://docs.python.org/3/library/statistics.html)). Works for now. `"`, if any, have to be escaped. 


## zsh prompt
Yet another change (theme file `clean2.zsh-theme`):
`PROMPT='%{$fg[green]%}(%*/%!) %{$fg[$NCOLOR]%}%B%b%{$reset_color%}%{$fg[blue]%}%B%5c/%b%{$reset_color%} $(git_prompt_info)%(!.#.$) '`

It transforms to:

`(10:23:09/10712) some/folder/whatever/ $ mycommand`

Removed the user (that I had to edit out often), moved current time from `PROMPT` to the left side (now I can happily copypaste CLI args and output again).


## regex greedy / lazy
[Regex Quantifier Tutorial: Greedy, Lazy, Possessive](https://www.rexegg.com/regex-quantifiers.html) TODO

TL;DR most regex engines are greedy by default. Greedy = 'longest possible match'. Making it lazy sometimes means adding a "?" to the quantifier, such as `.*?`. Not supported everywhere, notably grep does this only with the perl syntax (`grep -P .*?`).

For vim: [regular expression - How to make regex matchers non-greedy? - Vi and Vim Stack Exchange](https://vi.stackexchange.com/questions/196/how-to-make-regex-matchers-non-greedy/13363#13363)

## `info` command instead of `man`
Nice, had no idea this existed. `info diff`, for example.
Found here: [linux - Understanding of diff output - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/81998/understanding-of-diff-output).

## Unified diff how to read

`@@ -1,4 +1,5 @@`: 
> - The number after the comma is the length of the chunk (in the old or new file), and
> - the number before the comma is the line number for the beginning of the chunk.
> - The + and - signs refer to adding and deleting lines, respectively.  [^sounce]

[^sounce]: [What do the numbers in the @@ line mean in output of diff? - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/252927/what-do-the-numbers-in-the-line-mean-in-output-of-diff?noredirect=1&lq=1)

Gnu diff man page has more: [Detailed Unified (Comparing and Merging Files)](http://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html)

## Git / Jira / Bitbucket branches and connections to tickets
As long as the branch name contains the issue key (ABCD-123), it gets connected - but only if the branch is created _after_ the creation of the ticket. [^jibbranchsource]
> As stated previously in this question, it is not possible. You are screwed if you create the branch first.

But also it seems that mentioning an issue name in the pull request (does this work for commits?) also works:
> Simply renaming the Pull Request in Github to include the issue id XXX-nnn in the name triggered that PR and Branch to be linked to the Jira ticket.  [^jibbranchsource]

[^jibbranchsource]: [Solved: How to link existing JIRA issue to a existing bran...](https://community.atlassian.com/t5/Jira-questions/How-to-link-existing-JIRA-issue-to-a-existing-branch-in/qaq-p/701496)

## Random / i3 / workspaces
I could define a workspace officially, like number 5, for terminals I don't really need but that are open in deep folders I might need later.

## Random / documentation / dtb
Sometimes I miss the ability to drag and drop screenshots to my textfile with descriptions of stuff I did. I can drag and drop screenshots but they are a bit ephemeral. An interesting idea would be create a different keybinding that creates screenshots that get put in a particular folder; I can still drag-and-drop them, but I'll have stricter guarantees that they'll be there when I'll look for them.

## vim plugin MultipleSearch
[MultipleSearch - Highlight multiple searches at the same time, each with a different color. : vim online](https://www.vim.org/scripts/script.php?script_id=479)

```
:Search sth
:Search somethingelse
:SearchReset
```

Highlights them in diff colors, just what I need. `n/N` works only on the last one.

[vim-scripts/MultipleSearch2.vim: Improve Multiple search](https://github.com/vim-scripts/MultipleSearch2.vim) looks like an improved version of the above.

## vim search and substitute
You can use `\1` etc for `%s/..` commands, if the groups where previously defined by you in a usual `/search-for-stuff`! 
```
/\v(https?):\/\/(.{-})\/.*        <-- Search
:%s,,Protocol:\1 - Domain:\2,g    <-- Substitution
```

This is awesome.
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus