Use mouse wheel to scroll less in iTerm2

在 iTerm2 中使用 less command 有一个奇怪的点:你不能用鼠标来滚动页面。只能使用 Vim 的 keybinding Ctrl+d 和 Ctrl+u 来上下翻页。而且当你比如在查看一个 command 的 man page 时,因为 man page 默认是使用 less 来打开的,你查看完某个 man page 按 q 退出,然后使用鼠标滚轮往上面滚一下,滚到上面一屏,你会发现你的 Terminal 变得很乱,有很多刚刚你查看的那个 man page 的残留。 我的需求总结来说就是: 能够在 less 里使用鼠标滚轮来翻页,滚动。 退出 less 之后不要有残留。 其实,这里有一个概念叫作 alternate screen。你用 less 打开查看一个什么文件的时候进入的就是一个 alternate sceen,按 q 退出就是退出那个 alternate screen,回到 normal screen。Alternate screen 就是一个单独的 buffer,独立于当前 terminal 的。 When activated, the current screen is saved and replaced with the alternate screen.1 ...

2023-12-17

Use native file picker on KDE Plasma

For Firefox Starting with version 64, Firefox can optionally use XDG Desktop Portals to handle various desktop features, such as opening a file picker, or handling MIME types. — Arch Wiki | Firefox | XDG Desktop Portal integration Type about:config in Firefox address bar. Search widget.use-xdg-desktop-portal.file-picker, set it to 1. 0 – Never 1 – Always 2 – Auto (typically depends on whether Firefox is run from within Flatpak or whether the GDK_DEBUG=portals environment is set) Done. For VS Code These two environment variables: GTK_USE_PORTAL=1, GDK_DEBUG=portals. ...

2023-12-09

Pin apps to KDE Panel, not KDE Task Manager

比如你想把 Konsole 和 Firefox 这些最最常用的 app pin 到底部的 bar/dock 上(实际上 KDE 叫它 Panel),最直观的,你下意识的右键 Task Manager 上已经打开的 app,这里有一个“Pin to Task Manager”的选项,勾选上它。但这好像不是你想要的,因为你发现即使 pin 上去了,只要你打开那个 app 的一个 instance,那个刚刚被你 pin 上去的 app 就又不见了。这似乎不是你期待中的“pin”。这时你想要打开那个 app 的第二个 instance,就没法去到老地方,你最初 pin 它的那个地方打开。得找到现在的正在运行的那个 instance 所在的 Task Manager 的地方,右键 > “Open a New Window”。 其实,你刚刚 pin 上去的那个地方,是 Task Manager 的区域。Task Manager 外层还有一个区域,叫作 Panel。你应该,或者说你其实想把它 pin 到 Panel 上。这样不管你开几个 instance,那个 app 的图标还是在那,当你想开第 n+1 的 instance 的时候,还是去那个 pin 的地方点一下就行了。 总的来说,KDE 底部栏的层级是这样的: Panel: Application Launcher Pager Task Manager System tray Digital clock Peak at Desktop 你其实想把 Konsole 和 Firefox pin 到这里: ...

2023-12-04

sshfs

How to mount remote machine’s directory on current host? This question originally came up when I wanted to use Kate to edit a configuration file on macOS. I normally ssh into macOS, cd to that directory, and then type kate <file> to try opening the file for editing. But huh? There’s no kate command. Oh right, because I’m in the macOS environment, of course there’s no kate! But this is a problem - am I restricted to only using vi to edit remote files? I see Asahi Lina smoothly using Kate to open projects and files across multiple Mac machines around her to edit back and forth during development. There must be some way to make this work. ...

2023-12-03

gpg-agent doesn't work anyway!

Solved by this command: gpg-connect-agent updatestartuptty /bye >/dev/null

2023-12-02

btrfs and btrbk

/etc/btrbk/btrbk.conf config file: volume / snapshot_dir btrbk_snapshots subvolume home incremental strict Key points: volume /: “Base path within a btrfs filesystem containing the subvolumes to be backuped (usually the mount-point of a btrfs filesystem mounted with subvolid=5 option).” In this case, we use the existing root directory — which is already a btrfs filesystem (by default on Fedora). btrbk refer this / (next to volume) as “<volume-directory>”. snapshot_dir btrbk_snapshots: btrbk_snapshots is relative to the volume set above, which in this case the / (root directory). So the full path of btrbk_snapshots will be /btrbk_snapshots, which located just under the root directory. It’s like the “destination” of snapshots. subvolume home: home is also relative to / which set above. It’s the “source” of snapshots. There are also a target field can be set: target /mnt/btrbk_backup, but it’s optional. The target is where the “backup” subvolumes to be created (refer to the man page of btrbk.conf via man btrbk.conf), while the snapshot_dir is where “snapshot” to be stored. incremental strict: which means “non-incremental (initial) backups are never created” (man btrbk.conf). What is snapshot? ...

2023-12-01

GPG key for SSH authentication

Using GPG key for ssh authentication reduces the effort involved in managing SSH keys, which is the main reason I want to learn this technique. GPG key for all (not just one GPG key possibly).

2023-11-28

SSH notes

SSH 是一个我之前就想尝试使用的工具,当时只有对它的一个很简单的印象,就是可以通过它安全的访问另外一台电脑——的 Terminal。当然对它的具体原理和运行逻辑肯定是不了解的,包括它是怎么个安全法。只知道哦我可以通过它访问到比如说,当我自己打开 Terminal 时候首先展示在我面前的那一堆东西,其实就是在 $HOME directory 你输入比如 ls -al 命令出现的各个 directory。只是我可以看到另一台设备的这一堆东西。那当时这个需求也是没有那么强烈,所以就还是暂时搁置没有了解。 ...

2023-11-28

File size

Notes du * 输出的其实不是我们通常理解上的文件大小,而是所谓 block size(block count 可能更准确)。而且,它显示的是 disk usage,也就是这个文件占了多大的硬盘容量,或者说文件系统实际分配了多少空间给到这个文件。而不是,这个文件,它本身有多大。这个区别比较关键,后面会有更多的说明。 $ du * 5568 1-2-1_2frames_ap4h.mov 8040 1-2-1_2frames_ap4x.mov 3928 1-2-1_2frames_apch.mov 2152 1-2-1_2frames_apcn.mov 688 1-2-1_2frames_apco.mov 1592 1-2-1_2frames_apcs.mov 我们使用 exa 这个 ls 的替代,用 exa -lh -b -S 这个命令得到这样的输出: $ exa -lh -b -S Permissions Size Blocks User Date Modified Name .rw-r--r--@ 2.7Mi 5568 thom 27 Oct 17:32 1-2-1_2frames_ap4h.mov .rw-r--r--@ 3.9Mi 8040 thom 27 Oct 17:32 1-2-1_2frames_ap4x.mov .rw-r--r--@ 1.9Mi 3928 thom 27 Oct 17:32 1-2-1_2frames_apch.mov .rw-r--r--@ 1.0Mi 2152 thom 27 Oct 17:32 1-2-1_2frames_apcn.mov .rw-r--r--@ 342Ki 688 thom 27 Oct 17:32 1-2-1_2frames_apco.mov .rw-r--r--@ 793Ki 1592 thom 27 Oct 17:32 1-2-1_2frames_apcs.mov -l: Display extended file metadata as a table. -h: Add a header row to each column. -b: List file sizes with binary prefixes. --binary. -S: List each file’s number of file system blocks. 可以看到 Blocks 那一栏跟 du * 的输出是一样的。-S 的 flag 的作用也正是列出 file system blocks。 ...

2023-11-01

C++ Preprocessor

Excerpted from learncpp.com preprocessor .cpp file => preprocessor: Make change to the text of the code file, but not actually to the original code file, rather temporarily in-memory or using temporary files. Uninteresting things: strip out comments, ensures each code file ends in a newline. One important role: process#include directives. => What comes out of the preprocessor is called translation unit. The translation unit is then compiled by the compiler. The entire process of preprocessing, compiling and linking is called translation. ...

2023-09-21