organicCola's House

Organic cola is good for your happiness

0%

pre

you can copy files and folders in the iOS built-in Files app.

issue

But I found it won’t copy the dot files like .gitignore files, .git folders, which will cause some promlems.
For example, I have a git repository Repo_ain another root git repository Repo_A. I have a workflow about checking the Repo_a status and the execute git add --all in it, in the Repo_A I always use git add -u to avoid adding untracked files into the index. However when I copy the Repo_a into Repo_A, then try the workflow, I found the whole untracked files in the Repo_A has been add to the index as the execution results ought to have only work inside the Repo_a, because there is no .git folder in the Repo_a and it’s not recongnised as a git repository due to the copy function in Files app didn’t copy the .git folder.

Solution

So be careful with it, if you want copy the dot files in a folder in the Files app, maybe you could do it after zipping it.

Pre

Using ssh to login remote machine is a very common operation, but if you are tierd of being prompted for pass-phrases, you can use authorization key.

Issue

copy your public key under(usually it’s in ~/.ssh/id_rsa.pub), and append it to the target machine’s ~/.ssh/authorized_keys file, then the prompt for pass-phrases won’t block you.
but the operation can be very unconvinient, you have to copy it into your system clipboard and login target first to paste into the file. Especially when you are working on a pure tty, you don’t really have a system-wild clipboard to do the operation between local and the target machine, but you could still use tools like tmux to achieve it, they have a shared clipboard to sync everything across terminals.

Solution

I used to use tmux to do it until I found the ssh-copy-id. it can easily do the copy automatically.

Steps

you can add it to the authorized_keys to avoid being repeatedly prompted for pass-phrases
ssh-copy-id root@192.168.199.240

note that you should operate on the current, not the remote target machine.

tip: ssh-copy-id will use default_ID_file, basically it won’t have any problems, but if you have multiple public key files that matches id*.pub in your ~/.ssh/, the key being used may not the one you want, solve it refering to the following:

The default_ID_file is the most recent file that matches: ~/.ssh/id*.pub, (excluding those that match ~/.ssh/*-cert.pub) so if you create a key that is not the one you want ssh-copy-id to use, just use touch(1) on your preferred key’s .pub file to reinstate it as the most recent.

Pre

Sometimes we want mount files on the remote machine to our local. It’s a little bit like webDav, but actually based on another protocol ssh.

Issue

Tried brew install sshfs, indeed there’s a package there, but according to its description, it requires the linux system, which MacOS is not satisfied(though it’s an Unix-like one) the requirement, and actually the installation will fail.

Solution

Searching on the internet, found there is a sshfs from the osxfuse(it’s now macfuse which can let write to the ntfs format harddisk). there is an sshfs in its github repository.
and you could download the package from macFUSEinstead of compiling it yourself.

Steps

  • download the package from macFUSE and install it. You need to do the priviledge permission to sshfs and the restart mac.
  • mount
    1
    2
    mkdir ~/mnt
    sshfs root@192.168.1.101: ~/mnt
  • umount
    1
    umount ~/mnt
    sometimes if encounter an error try
    1
    umount -f ~/mnt

Pre

if you use powerline on Windows, then you may be familiar with the “right click to paste from system board” feature.

Issue

on Unix-like system, I’d rather tmux in my workflow in which I found right click doesn’t behave like what it does on Windows.

Slolution

Luckily, we could config it.

Steps

1
2
3
# ~/.tmux.conf
# mouse binding
bind-key -T root MouseDown3Pane run-shell 'pbpaste | tmux load-buffer - \; paste-buffer -p'

-T indicates that we only change the keybinding under the root Key Table(you can check it by prefix+:customize mode)
no need to use the following repository, but found useful tmux config for pasting from system pasteboard here
ref: tmux-MacOSX-pasteboard

pre

when using a tty console on archlinux, we can’t set the cursor style (like underline or block for example) in a intuitive way like in the GUI based OS where we’re allowed to do the tweak by simply change the setting in the console emulator.
luckily we could use the command echo to achieve the goal.
like the following:

1
echo -e '\e[?6c'

issue

but when running applications like vim or tmux, the cursor reverts back to being a blinking gray underscore.

solution

after searching I found something on the stackexchange.

Most apps use the cnorm capability to set the cursor back to the “normal” state. By default this is the blinking underline. But you can override this in your terminfo. This should fix most applications (vim, tmux, etc.). Issue
ref: How to change cursor shape, color, and blinkrate of Linux Console?

steps

The following should create ~/.terminfo/l/linux which should be picked up by most of the terminal apps.

the following will generate a file which we can use to modify the ~/.terminfo/l/linux later in the current working directory.

1
infocmp -A /usr/share/terminfo linux > linux

according to the following, modify the file.

1
2
3
4
5
6
7
8
9
10
11
12
--- a/linux
+++ b/linux
@@ -4,7 +4,7 @@ linux|linux console,
colors#8, it#8, ncv#18, pairs#64,
acsc=+\020\,\021-\030.^Y0\333\`\004a\261f\370g\361h\260i\316j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\
bel=^G, blink=\E[5m, bold=\E[1m, civis=\E[?25l\E[?1c,
- clear=\E[H\E[J, cnorm=\E[?25h\E[?0c, cr=^M,
+ clear=\E[H\E[J, cnorm=\E[?25h\E[?48;0;32c, cr=^M,
csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
EOF

apply the change to the ~/.terminfo/l/linux

1
2
tic linux
rm linux

Pre

vitetris is a Virtual terminal tetris clone, you could play it in the tty, it even support two palyers at the same time.
in macOS the installation goes fine with homebrew, while the situation is not good at the archlinux.
you can install it using yay which is a package manager based on the AUR(Archlinux User Repository), bucause it’s not included in the official pacman.

Issue

but the sources in the aur has some problem, you may can’t pass the comilation and building.

Solution

searching on the aur, and found the vitetris’s PKGBUILD has some problems blocking build steps.

It seems like printf needs a string format, so I add this line to the end of prepare() in PKGBUILD. It successfully builds with this fix.
sed -i 's|ctime(&t)|"%s", &|' src/netw/gameserver.c
ref: vitetris in aur

so fix it in PKGBUILD, and rebuild it, then install it.

Step

fix the PKGBUILD

fix it in PKGBUILD

1
2
3
4
5
6
7
8
9
10
# ~/.cache/yay/vitetris

prepare() {
cd ${pkgname}-${pkgver}
patch -Np1 -i "${srcdir}"/${pkgname}-makefile.patch

# Change configuration file to a standard one:
sed -i 's|#define CONFIG_FILENAME ".vitetris"|#define CONFIG_FILENAME ".config/vitetris"|' src/config2.h
sed -i 's|ctime(&t)|"%s", &|' src/netw/gameserver.c
}

rebuild & install it.

1
makepkg -si

play

run it with vitetris

Pre

Sometimes we use Ctrl-s to do a i-search command history when use GNU Readline in some programs like mysql and python.
but when I try it on a linux machine it stuck and freeze the program.

Solution

After searching on the Internet, I found the keystroke Ctrl-s has some special meaning in the linux, it is not the keybind conflict on the term of your shell or GNU Readline, it’s an issue on the term of OS.

how-to-unfreeze-after-accidentally-pressing-ctrl-s-in-a-terminal
This stop/start scheme is software flow control, which is implemented by the OS’s terminal device driver rather than the shell or terminal emulator. It can be configured with the stty command.
To disable it altogether, put stty -ixon in a shell startup script such as ~/.bashrc or ~/.zshrc. To instead just allow any key to get things flowing again, use stty ixany.

Step

with the following setting, it should work.

1
2
# ~/.zshrc
stty -ixon

pre

when use mysql in linux, the keybinding doesn’t behave like what it does in the common zsh.

in zsh, I customize some keybinding, like use C-j/k two move between word.

1
2
bindkey "^K" forward-word
bindkey "^J" backward-word

however I found it breaks in the mysql.
and, actually it breaks in many applications, like python cli.

solution

then I found the ~/.inputrc
it will affect all applications that use GNU Readline library.
which mysql cli is of course be affected by this.

1
2
3
vim `~/.inputrc`
"\C-j": backward-word
"\C-k": forward-word

pre

有线音箱连接在PC上,平时想把播放音乐时会使用PC。但是有时候想要切歌或调整音量时,如果并没有在操作pc就不得不专程去手动操作一下,很麻烦。
有没有一个iOS app可以遥控pc端的音乐播放呢。

solution

然后我发现了apple官方的一个app apple remote

与pc上的itunes配对后,就可以在iOS端实现播放控制:音量调节,切换歌曲,更换编辑歌单等。

pros

  • 免费。很多类似的remote app都对此类操作升级收费。
  • 播放音乐和手机操作和互不干扰,音源在pc上,没有传输的问题,播放高码率文件时候有优势。
  • 不需要额外购置蓝牙音箱,高品质蓝牙音箱价格不菲。
  • 只在需要操作的时候发生交互。
  • apple自家的产品,交互和功能都很舒适。

cons

  • 不如airplay蓝牙音箱方便,可以直接播放手机上内容。
  • 需要多一台电脑开着。

Pre

在iOS里你可以通过点击顶部状态栏来让页面滚动到顶部,但是似乎没有一个直接到达底部的触发方法。其实我们可以利用滚动条来变相实现。

Solution

如果在滑动屏幕时,趁右侧滑动条还没有消失,长按它,你就可以拖动它,这时候可以快速地在整个页面滑动,到达页面底部也就更容易了。