Arch Linux Notes

This is my notebook for some small tips and tricks when using Arch Linux.

Why Arch Linux?

  • It is fresh and simple in package dependency.

  • It has a powerful Arch User Repository and makes it easy for you to make/modify your package.

  • It has a detailed Arch Wiki comprising useful experiences and recommendations.

  • It gets you to learn the basic knowledge required to be a Linux user/administrator/programmer.

Refer to manual

Use man [SECTION] <NAME> to show a manual.

Use whatis <NAME> to find out which sections are available in manual.

Use apropos <KEYWORD> to search for manuals whose name or description contains certain keyword.

Use man man-pages to see the definition of each seciton.

Use help -m <BUILTIN> to show help for a shell builtin in manual page format.

The “SEE ALSO” section in a manual sometimes can be very helpful.

You can also use man hierto get to know the Linux filesystem hierarchy.

Find available commands

Shell builtin compgen can list possible completions for your input.

NTFS partitions auto mounting

  1. Use gnome-disks, select partition and click the settings button below, click and then modify mount options in the popup menu.

  2. Install ntfs-config and enable auto mounting.

Disable Nvidia graphics

Install bbswitch.

And create /etc/modprobe.d/nouveau_blacklist.conf as follow, or else bbswitch will find Nvidia graphics in use by nouveau.

1
blacklist nouveau

You can verify bbswitch status by cat /proc/acpi/bbswitch and view its log by dmesg | grep bbswitch.

Note that the nouveau kernel module is shipped in linux.

Also note that if your install bumblebee, it will ship the blacklist file for you.

Hardware video acceleration

See Arch Wiki.

If mkv playback doesn’t work well in VLC, remove libvdpau-va-gl.

Shrink pacman cache

From Arch Wiki:

paccache -r deletes all the cached versions of each package except for the most recent 3 (without confirmation).

paccache -ruk0 removes all the cached versions of uninstalled packages.

See paccache -h for dry run and other parameters.

Better diff

alias diff='git diff --no-index' works great with the only requirement of git.

Make programs use proxy

There are several ways to make a program proxied. Part of the following comes from Arch Wiki.

  • Environment variables

    Some programs respect proxy set via environment variables.

    1
    2
    3
    4
    5
    export http_proxy=http://10.203.0.1:5187/
    export https_proxy=$http_proxy
    export ftp_proxy=$http_proxy
    export rsync_proxy=$http_proxy
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

    It is sometimes advised that you export these environment variables again, with their names upper cased.

  • Proxychains

    Install proxychains-ng. Proxychains hooks some C library functions so that programs gets proxied. However the Java VM cannot be proxied this way.

    1
    proxychains <YOUR_PROGRAM>
  • Java

    From the documentation of Java:

    • HTTP

      • http.proxyHost: the host name of the proxy server

      • http.proxyPort: the port number, the default value being 80.

      • http.nonProxyHosts: a list of hosts that should be reached directly, bypassing the proxy. This is a list of patterns separated by ‘|’. The patterns may start or end with a ‘*’ for wildcards. Any host matching one of these patterns will be reached through a direct connection instead of through a proxy.

    • HTTPS

      • https.proxyHost

        https.proxyPort

    • FTP

      • ftp.proxyHost (Typo in official documentation)

      • ftp.proxyPort

      • ftp.nonProxyHosts

    • SOCKS

      • socksProxyHost for the host name of the SOCKS proxy server

      • socksProxyPort for the port number, the default value being 1080

      • socksProxyVersion for the version of the SOCKS protocol, the default being 5, and alternatively 4 can be specified.

      Note: socksProxyVersion and more properties are documented at another documentation of Java.

      Sample usage:

      1
      java -Dhttp.proxyHost=webcache.example.com -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts='localhost|host.example.com'

      Or you can utilize _JAVA_OPTIONS:

      1
      export _JAVA_OPTIONS="-DsocksProxyHost=localhost -DsocksProxyPort=10801"

Note that you can tunnel http(s) request to local socks client using Polipo, for example polipo socksParentProxy=localhost:10800.

Touchpad settings and horizontal two-finger scrolling doesn’t work

GNOME dropped support for synaptics driver due to luck of maintenance in version 3.20.

Remove xf86-input-synaptics and xf86-input-evdev, install xf86-input-libinput, then reboot.

GNOME proxy setting

You can utilize GNOME’s proxy setting in Settings > Network even if you use netctl instead of Network Manager (Disabled in recent GNOME, see below). Both HTTP and SOCKS proxy are supported.

You can also modify proxy setting with dconf-editor, Set system.proxy.mode to manual, then set your proxy in system.proxy.{ftp,http,https,socks}.

Note that the proxy setting will also be read and set to corresponding environment variables by gnome-terminal, and no option is offered to turn this behavior off. To avoid setting proxy environment variables, reset the environment variables in your .bashrc.

1
2
3
4
# Unset global proxy set by gnome-terminal
# See https://github.com/GNOME/gnome-terminal/blob/master/src/terminal-util.c
unset http_proxy https_proxy ftp_proxy all_proxy no_proxy
unset HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY NO_PROXY

GNOME online account

You can log in your Google account and all the things will be configured and synchronized automatically to your laptop. It can be a huge boost for your work flow.

If you need a proxy to access Google, configure it as in the GNOME proxy setting section.

Save ssh key passphrase to keyring

As in Arch Wiki, use seahorse-ssh-askpass.

As of seahorse 3.18.0-2, SSH_ASKPASS is not exported by default anymore, so you will need to add the following lines to your /etc/profile.

1
2
# Set ssh askpass
SSH_ASKPASS=/usr/lib/seahorse/seahorse-ssh-askpass

Nautilus hangs occasionally

In my case it often happened when I started to search something. Turned out that it is caused by my putting too many files under indexed directories.

To fix the hang up, launch tracker-preferences, go to “Locations” tab, and turn off “Recurse” for directories you may store a large amount of files. Then execute tracker reset --hard to reset tracker index and configurations. This resolved my issue so far.

DNS and resolvconf

DNS is managed by resolvconf in Arch Linux. In order to supply your own DNS, edit /etc/resolvconf.conf.

There are two options you may normally want to specify:

1
2
name_servers=<DNS1> #Prepended into DNS list
name_servers_append="<DNS2> <DNS3> ..."

After modification, you may want to execute resolvconf -u to update resolv.conf.

Note that dhcpd also setup DNS for interfaces via resolvconf, in /run/resolvconf/interface/<INTERFACE>. You can override its behavior by executing dhcpcd -S domain_name_servers=<DNS>, or inside dhcpcd.conf.

Boost entropy

If the output of cat /proc/sys/kernel/random/entropy_avail is less than 1000, you need to install and enable havedged.

1
2
3
sudo pacman -S havedged
sudo systemctl enable havedged
sudo systemctl start havedged

Create software AP (Access Point), a.k.a. virtual WiFi

Install AUR package create_ap; you may want to remove the wifi.service it automatically creates when installed and use your own.

Check the Capabilities section in iw list along with /usr/share/doc/hostapd/hostapd.conf to determine ht_capab.

Note that in ZJU, ZJUWLAN occupies channel 1 and 6, so you’d better specify another channel.

Sample systemd service:

File: <YOUR_SSID>@.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=Create AP service for <YOUR_SSID>
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/create_ap -c 13 -w 2 -m nat --ieee80211n --ht_capab [HT40-][HT40+][SMPS-STATIC][GF][SHORT-GI-20][SHORT-GI-40][DSSS_CCK-40] <YOUR_WLAN_INTERFACE> %i <YOUR_SSID> <YOUR_PASSPHRASE>
ExecStop=pkill hostapd
KillSignal=SIGINT
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target

However on my own machine, I cannot share a secure (with password) network.

Analyze network issue

Use mtr(My traceroute), a tool combining much of the functionality of ping and traceroute into one interface.

Raise inotify limit for IntelliJ IDEA

Write the following line to /etc/sysctl.d/99-custom.conf

1
fs.inotify.max_user_watches = 524288

Sysrq

Write the following line to /etc/sysctl.d/99-custom.conf to enable all the sysrq operations.

1
kernel.sysrq = 1

Reboot to make changes take effect, or execute echo 1 >/proc/sys/kernel/sysrq.

Hold Alt, and press the following key sequence.

  1. SysRq
  2. R unRaw
  3. E tErminate
  4. I kIll
  5. S Sync
  6. U Unmount
  7. B reBoot

Note that the key C can make your kernel panic immediately.

Watch FS buffer status

1
watch grep -e Dirty: -e Writeback: /proc/meminfo

You can execute sync to flush the buffer immediately.

Map Alt Gr (Right Alt) to Alt in tty

From Arch Wiki

1
2
3
cd /usr/share/kbd/keymaps/i386/qwerty
cp us.map.gz us-two-alt-keys.map.gz
gunzip us-two-alt-keys.map.gz

Edit us-two-alt-keys.map,replace include "linux-with-alt-and-altgr" with include "linux-with-two-alt-keys".

1
gzip us-two-alt-keys.map

Edit /etc/vconsole.conf, replace KEYMAP=us with KEYMAP=us-two-alt-keys.

Reboot.

Better bash.bashrc

Originally from Arch Wiki, but now the page is deleted. Anyway you can still access its Chinese version.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# /etc/bash.bashrc
#
# https://wiki.archlinux.org/index.php/Color_Bash_Prompt
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !
# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
# If not running interactively, don't do anything!
[[$- != *i*]] && return
# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control.
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize
# Enable history appending instead of overwriting.
shopt -s histappend
case ${TERM} in
xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
;;
screen*)
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf"\033_%s@%s:%s\033\\""${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
;;
esac
# fortune is a simple program that displays a pseudorandom message
# from a database of quotations at logon and/or logout.
# If you wish to use it, please install "fortune-mod" from the
# official repositories, then uncomment the following line:
# [["$PS1"]] && /usr/bin/fortune
# Set colorful PS1 only on colorful terminals.
#
# 2016-02-11
# ZH: We are using `tput colors` because the new version of
# `dircolors` added globbing in its database, making the old method
# broken. So we are switching to `tput colors` now.
# Below is the old method by checking `dircolors`.
#
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS. Try to use the external file
# first to take advantage of user additions. Use internal bash
# globbing instead of external grep binary.
#
# sanitize TERM:
#safe_term=${TERM//[^[:alnum:]]/?}
#match_lhs=""
#
#[[-f ~/.dir_colors]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
#[[-f /etc/DIR_COLORS]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
#[[-z ${match_lhs}]] \
# && type -P dircolors >/dev/null \
# && match_lhs=$(dircolors --print-database)
#
#if [[$'\n'${match_lhs} == *$'\n'"TERM"${safe_term}*]] ; then
if type -P tput >/dev/null && tput colors >/dev/null 2>&1 && [["$(tput colors)" -ge 0 ]] ; then
# we have colors :-)
# Enable colors for ls, etc. Prefer ~/.dir_colors
if type -P dircolors >/dev/null ; then
if [[-f ~/.dir_colors]] ; then
eval $(dircolors -b ~/.dir_colors)
elif [[-f /etc/DIR_COLORS]] ; then
eval $(dircolors -b /etc/DIR_COLORS)
fi
fi
# Enable __git_ps1
if [[-f /usr/share/git/git-prompt.sh]]; then
source /usr/share/git/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM=auto
PS1="$(if [[ ${EUID} == 0]]; then echo'\[\033[01;31m\]\h'; else echo'\[\033[01;32m\]\u@\h'; fi)\[\033[01;34m\] \w\[\033[01;33m\]\$(__git_ps1' (%s)') \[\033[01;34m\]\$([[\$? != 0]] && echo'\[\033[01;31m\]:(\[\033[01;34m\] ')\\$\[\033[00m\]"
else
PS1="$(if [[ ${EUID} == 0]]; then echo'\[\033[01;31m\]\h'; else echo'\[\033[01;32m\]\u@\h'; fi)\[\033[01;34m\] \w \$([[\$? != 0]] && echo \"\[\033[01;31m\]:(\[\033[01;34m\] \")\\$\[\033[00m\]"
fi
# Use this other PS1 string if you want \W for root and \w for all other users:
# PS1="$(if [[ ${EUID} == 0]]; then echo'\[\033[01;31m\]\h\[\033[01;34m\] \W'; else echo'\[\033[01;32m\]\u@\h\[\033[01;34m\] \w'; fi) \$([[\$? != 0]] && echo \"\[\033[01;31m\]:(\[\033[01;34m\] \")\\$\[\033[00m\]"
alias ls="ls --color=auto"
alias dir="dir --color=auto"
alias grep="grep --color=auto"
alias dmesg='dmesg --color'
# Uncomment the "Color" line in /etc/pacman.conf instead of uncommenting the following line...!
# alias pacman="pacman --color=auto"
else
# show root@ when we do not have colors
PS1="\u@\h \w \$([[\$? != 0]] && echo \":(\")\$"
# Use this other PS1 string if you want \W for root and \w for all other users:
# PS1="\u@\h $(if [[ ${EUID} == 0]]; then echo'\W'; else echo'\w'; fi) \$([[\$? != 0]] && echo \":(\")\$"
fi
PS2=">"
PS3=">"
PS4="+"
# Try to keep environment pollution down, EPA loves us.
#unset safe_term match_lhs
# Try to enable the auto-completion (type: "pacman -S bash-completion" to install it).
[-r /usr/share/bash-completion/bash_completion] && . /usr/share/bash-completion/bash_completion
# Try to enable the "Command not found" hook ("pacman -S pkgfile" to install it).
# See also: https://wiki.archlinux.org/index.php/Bash#The_.22command_not_found.22_hook
[-r /usr/share/doc/pkgfile/command-not-found.bash ] && . /usr/share/doc/pkgfile/command-not-found.bash
# ZH: carry alias to sudo.
alias sudo="sudo"
# ZH: make rm safer.
alias rm="rm -i"

Bash completion

To enabling cyclic completion on tab, add the following line to your .bashrc:

1
bind '"\t": menu-complete'

To get more completion with specific commands, install package bash-completion.

Bash command not found hook

Install package pkgfile.

Execute previous commands in bash

Ctrl+R (I-search backward in emacs) can let you quickly execute command in your history.

!! is substituted to be the last command in your history, but be careful when using it, for example echo !! will lead to unexpected behavior if !! is substituted to be something && poweroff, then poweroff will be executed. To avoid such cases, always wrap it with quotes, like echo "!!".

Input tab or newline character in bash

Ctrl+V in bash works as Ctrl+Q in emacs, which will insert the next character literally.

Edit current command in editor

Press Ctrl+X then Ctrl+E, and then you’ll be able to edit the current command in your editor before execution.

Access clipboard in bash

Install package xsel. Add alias xsel='xsel -b' to your .bashrc, and then you can use it like xsel <input_file or xsel >output_file.

Default font

To specify your preference on default fonts, create /etc/fonts/local.conf, and edit it like the following example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match>
<test name="family"><string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="strong">
<string>WenQuanYi Micro Hei</string>
<string>WenQuanYi Zen Hei</string>
<string>WenQuanYi Bitmap Song</string>
<string>DejaVu Sans</string>
<string>Noto Color Emoji</string>
</edit>
</match>
<match>
<test name="family"><string>serif</string></test>
<edit name="family" mode="prepend" binding="strong">
<string>DejaVu Serif</string>
<string>WenQuanYi Bitmap Song</string>
<string>WenQuanYi Zen Hei Sharp</string>
<string>AR PL UMing CN</string>
<string>AR PL UMing TW</string>
<string>AR PL New Sung</string>
<string>Noto Color Emoji</string>
</edit>
</match>
<match>
<test name="family"><string>monospace</string></test>
<edit name="family" mode="prepend" binding="strong">
<string>WenQuanYi Micro Hei Mono</string>
<string>WenQuanYi Zen Hei Mono</string>
<string>WenQuanYi Bitmap Song</string>
<string>DejaVu Sans Mono</string>
<string>Noto Color Emoji</string>
</edit>
</match>
</fontconfig>

Now you have appropriate fonts for sans-serif, serif and monospace as default.

For more information, see Arch Wiki.

Emoji font

Install noto-fonts-emoji.

Install local font

From Arch Wiki:

Drop your font files into ~/.local/share/fonts/ (~/.fonts/ is deprecated), cd into that directory, and execute the following command.

1
2
3
4
5
echo -n "Updating font cache..."
fc-cache >/dev/null -f
mkfontscale
mkfontdir
echo done

CJK font not showing in some PDF viewers

Install poppler-data.

Handle filesystem package update

Use diff and your editor to manually merge your passwd, shadow, group and gshadow with the *.pacnew one(s), then execute pwconv and groupconv for updating the shadow ones (*-).

Sync time with NTP

1
2
sudo pacman -S ntp
sudo ntpd -gq && sudo hwclock -w

For more information, see Arch Wiki.

Analyze boot time

1
2
systemd-analyze blame
systemd-analyze critical-chain

For more information, see man systemd-analyze.

Sometimes man-db.service may slow down the booting drastically, see this thread, this issue, and this issue.

Sometimes journald can slow down the booting for having too many journal files, see this Arch Wiki to set an limit on old journal files and clean them up.

System backup using tar

Install AUR package system-tar-and-restore.

Example: /etc/backup.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Configuration file for backup.sh script.
# Place it in /etc/backup.conf and edit it to your needs.
# Set the interface. Available options: cli dialog.
BRinterface="cli"
# Uncomment to disable colors.
#BRnocolor="Yes"
# Uncomment to enable verbose archiver output.
#BRverb="Yes"
# Set the destination directory. Default is /.
BRFOLDER="/run/media/zh/ZH-HDD/"
# Uncomment to set alternative archive name. Default is 'Backup-$(hostname)-$(date +%d-%m-%Y-%T)'.
#BRNAME="my_backup"
# Set the archiver. Available options: tar bsdtar.
BRarchiver="tar"
# Set the compressor. Available options: gzip bzip2 xz none.
BRcompression="gzip"
# Uncomment to keep /home's hidden files and folders only.
#BRhome="No"
# Uncomment to completely exclude /home directory. Use with BRhome="No".
#BRhidden="No"
# Uncomment to set additional archiver options.
BR_USER_OPTS="--exclude=/var/cache/* --exclude=/home/zh/.cache/* --acls --xattrs"
# Uncomment to disable genkernel check in gentoo.
#BRgenkernel="No"
# Uncomment to be quiet.
#BRquiet="Yes"

To start a backup, execute backup.sh as root.

Rename files with number

1
find -name '*.png' | sort -n -r | gawk '{ printf"mv %s %03d.png\n", $0, NR }' | bash

100 files, reversely:

1
find -name '*.png' | sort -n -r | gawk '{ printf"mv %s %03d.png\n", $0, 100 - NR }' | bash

Starting with 100:

1
find -name '*.png' | sort -n -r | gawk '{ printf"mv %s %03d.png\n", $0, 100 + NR }' | bash

Shell calculator

From an AskUbuntu question.

Add the following lines to your .bashrc.

1
2
3
4
=() {
input="${@//pi/π}"
echo -ne "$input\nquit" | gcalccmd | sed 's:^> ::g'
}

For example, = "e^(i*pi)+asin(1)/90" gives 0.

Use English-named XDG user directories

As in Arch Wiki, execute LC_ALL='en_US.UTF-8' xdg-user-dirs-update.

GNOME 3 start up applications

As of GNOME 3.12, gnome-session-properties is removed. Instead, launch gnome-tweak-tool and go to the corresponding tab. If you cannot add a start up application (the add button not responding), try launching gnome-tweak-tool from your terminal.

To truly manage your start up applications, go to ~/.config/autostart/ and edit the desktop files there.

Pomodoro for GNOME 3

Install AUR package gnome-shell-pomodoro.

Clipboard management tool for GNOME 3

Install AUR package gpaste, restart GNOME shell and enable the extension GPaste.

View video codec information

Use ffprobe.

Clip video

From StackOverflow:

If you want to support video players without edit list support (or actually drop the unused frames), you need to do a re-encode, which is the default if copy is not specified.

Normally, you can use the following command to clip a video:

1
ffmpeg -i <INPUT_FILE> [-ss <START_TIME>] [-to <STOP_TIME>] [-async 1] <OUTPUT_FILE>

Convert video to animated GIF

Adapted From dtbaker and a SuperUser question.

1
2
3
mkdir frames
ffmpeg -ss <HH:MM:SS[.XXX]|START_SECONDS> -t<HH:MM:SS[.XXX]|DURATION_SECONDS> -i <YOUR_VIDEO_FILE> [-r <FPS>] -s <WIDTH_NORMALLY_480>x<HEIGHT_NORMALLY_270> ./frames/frame%04d.png
convert -delay <100/FPS> -loop 0 -layers Optimize ./frames/frame*.png output.gif

If you need to compress your GIF file, use gifsicle or do it online; for cropping, you also can use this site with option “Crop with Gifsicle” (ImageMagick output seems corrupted).

Convert SVG to PNG (or else)

1
inkscape --export-png=<OUTPUT_FILE> --export-width=<WIDTH> --export-height=<HEIGHT>

--export-dpi is also available.

See man inkscape for more formats.

Convert PDF to PNG

From StackOverflow.

1
convert -density 300 <YOUR_FILE.pdf> <YOUR_FILE.png>

Where the -density parameter is your desired DPI.

Note that the -density parameter must come before the input file, or it won’t take effect.

Bitmap operation

Resize:

1
mogrify -interpolate bicubic -resize 50% *.png

Crop:

1
mogrify -crop 1080x1845+0+75 *.png

Merge PDFs

1
pdfunite <SOURCE_PDF_FILES> <OUTPUT_PDF_FILE>

Convert GB* encoded mp3 tag to Unicode

Install package easytag.

Note that EasyTag may become the handler for MIME type inode/directory, instead of your own file manager, say, Nautilus. You can delete the default association for Easytag and inode/directory in ~/.local/share/applications/mimeapps.list, which is managed by gvfs-mime. See also the MIME type section.

Play FLAC with CUE

Use deadbeaf. Rhythmbox cannot handle CUE due to its library design.

Install deadbeef-mpris2-plugin if you want MPRIS2 support (Controlling media playback in GNOME shell and other places).

Install deadbeef-gnome-mmkeys-git if you want media key support (Needs to be enabled in this plugin’s configuration after installation).

Edit FLAC metadata

Use metaflac from the flac package.

Test FLAC integrity

Use flac --test <YOUR_FLAC_FILE>.

Synchronize directories

Use freefilesync.

Use adb-sync from the adb-sync-git for Android.

MIME type handling

In GNOME, there are two components managing the default application for a MIME type.

The first one, which is system-wide, can be queried or set via xdg-mime.

The second one, which is a per-user setting, can be queried or set via gvfs-mime, or manually editing ~/.local/share/applications/mimeapps.list.

The second one takes precedence, and I guess gvfs-mime is implemented partially for GNOME Open with dialog.

Google URL in Google Chrome

Open ~/.config/google-chrome/Default/Preferences, edit last_known_google_url and last_prompted_google_url.

If Chrome keeps reverting the url, visiting https://www.google.com/ncr may help.

Screenshot

Shortcut keys for screenshot is listed in the search category of its setting.

  1. Screen to file: PrtSc

  2. Window to file: Alt + PrtSc

  3. Area to file: Shift + PrtSc

  4. To clipboard instead: Ctrl + above

  5. Record: Shift + Ctrl + Alt + R

To open a dialog for settings before screenshot, execute gnome-screenshot -i.

Resize window for screenshot

Enable the Screenshot window sizer extension in gnome-tweak-tool, then you can use Ctrl+Atl+S to cycle through a list of 16:9 window sizes.

Save screenshot to clipboard when PrtSc

Swap the values of org.gnome.settings-daemon.plugins.media-keys.{,area-,window-}screenshot{,-clip}.

Use PrtSc key for Menu

On my ThinkPad T450, the usual location for Menu key is a PrtSc key. I tried to change it with xmodmap, but it cannot get automatically loaded by my GNOME 3 — even when using autostart. Seems that it gets reset by some others, but even disabling a GNOME keyboard plugin as per a post in Arch Linux BBS did not help. And some other people say xmodmap has been deprecated; people should use xkb instead.

So in the end, I resorted to xkb, and dirtily modified /usr/share/X11/xkb/symbols/pc, swapping PRSC, Menu and INS, as follows.

1
2
3
4
5
6
7
8
9
10
11
12
32c32
< key <MENU> { [Menu] };
---
> key <PRSC> { [Menu] };
67c67
< key <PRSC> {
---
> key <INS> {
76c76
< key <INS> { [Insert] };
---
> key <MENU> { [Insert] };

Control ThinkPad battery charging

tp_smapi has been out of date for a long time, and it did not support my T450. Newer models of ThinkPad should use tpacpi-bat instead.

For simplicity, there is a tp-battery-mode package. Install it, enable and start the service, and you are done.

Recover lost free space on Ext2/3/4 partitions

Ext2/3/4 filesystem keeps 5% of its blocks reserved and usable only by root, which ensures that a normal user cannot fill the whole disk and cause the system to fail.

However on data partitions such as /home, this might be a waste of space. To get around this limitation, run sudo tune2fs -m 0 /dev/sdXX, which can be done online.

Draw graphs

LibreOffice Draw, and use its connectors instead of bare wires. Shift for regular shape and Ctrl + Mouse move for cloning can also be handy.

Render GFM

Bash script from jaburn’s gist.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env bash
data="$(
cat"$1"\
| sed's/"/\\"/g'\
| sed':a;N;$!ba;s/\n/\\n/g'\
)"
if [[-z "$2" ]]; then
context=''
else
context=",\"context\":\"$2\""
fi
echo '<!DOCTYPE html>'
echo '<html><head><style>'
curl -s 'https://gist.githubusercontent.com/andyferra/2554919/raw/2e66cabdafe1c9a7f354aa2ebf5bc38265e638e5/github.css'
echo '</style></head><body>'
curl -s --data "{\"text\":\"$data\",\"mode\":\"gfm\"$context}" 'https://api.github.com/markdown'
echo '</body></html>'

Generate mosaic image

See this question.

Minecraft with Forge crashes on splash screen

Sometimes Minecraft with Forge can crash with a message like the following one:

1
[xcb] Unknown request in queue while dequeuing

Disabling the Forge splash screen by setting enabled=false in .minecraft/config/splash.properties can workaround this problem.

Cannot start graphical application under su or sudo on XWayland

Execute xhost +local: to allow local connections to X server.

Better Rhythmbox UI design

Install and enable Alternative Toolbar.

Install Xilinx ISE

Modified from Arch Wiki:

  1. Download Xilinx ISE Installer from here.
  2. Install ncurses5-compat-libs, it is a required dependency of the installer.
  3. Untar only the first image, execute sudo xsetup, choose system edition, uncheck sending data, and leave other options the default. You don’t need to check the “Install cable driver” option. Don’t try to build a custom package for it; it’s painful and buggy.
  4. Fix libstdc++.so as in here.
  5. Install Digilent USB-JTAG drivers as in here. You don’t need to install fxload, or add yourself to the uucp group, or add a udev rule. You can program the device with the command djtgcfg with digilent.adept.utilities installed.
  6. Create ~/.local/share/applications/xilinx-ise.desktop as in here. My alternative version is given below.
  7. Get a license, and feed it to the license manager.

xilinx-ise.desktop:

1
2
3
4
5
6
7
8
9
10
11
[Desktop Entry]
Categories=Development;
Comment=Xilinx ISE
Encoding=UTF-8
Exec=sh -c "unset LANG && unset QT_PLUGIN_PATH && source /opt/Xilinx/14.7/ISE_DS/settings64.sh && export PRINTER=null && ise"
GenericName=Xilinx ISE
Icon=/opt/Xilinx/14.7/ISE_DS/ISE/data/images/pn-ise.png
Keywords=Xlinx;ISE
Name=Xilinx ISE
StartupNotify=true
Type=Application

By adding export PRINTER=null you can print schematic file to PDF once per launch. This is a bug in Xilinx ISE.

Additional tools

  • ack: grep replacement.
  • cloc: Count lines of code.
  • dos2unix: Convert End-of-line and some encoding to Unix flavor.
  • dosfstools: mkfs.fat, etc.
  • easytag: MP3 tag editing and conversion.
  • gpaste: Clipboard manager
  • gsmartcontrol: Graphical SMART viewer.
  • haveged: Boost low entropy.
  • htop: top replacement.
  • iotop: top on I/O.
  • jq: Manipulate JSON in command line.
  • lsof: List opened files.
  • mtr: traceroute + ping, automatically.
  • nload: Display current network usage.
  • ntfs-3g: NTFS writing support, and others.
  • pastebinit: Various pastebin services.
  • pdfgrep: grep on PDF.
  • powertop: Show power consumption.
  • profile-cleaner: Optimize browser profile SQLite database, and more.
  • proxychains: Proxify other programs.
  • pv: View progress for dd, etc.
  • rlwrap: Wrap programs with readline style input.
  • tig: Git repository browser.
  • translate-shell: Command-line translator using Google Translate or others.
  • trash-cli: Trash bin in command line.
  • tree: ls recursively in tree format.
  • vipe: Run editor in middle of a pipeline.
  • vlc: Versatile and stable video player.