Tagged: how_to

Building My Work Environment (Part 6)

Part 6 - Let's type in Japanese

Now, we can view Japanese in terminal, let's try installing some input method framework. The CHANGES_AND_HINTS.TXT for Slackware64 14.2 suggests to use SCIM, but according to Arch wiki, SCIM is a dead project now. So, we'll try installing IBus.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. This information below is solely used for my purpose and may not be suitable for others.

Installation:

Installation of ibus as well as its dependencies and Japanese engine, ibus-anthy, is no difficult tasks. If you are planning to input Japanese characters, you might consider installing ibus-qt as well. They are available from Slackbuilds.org as usual.

Configurations:

Once the installation is done, start the setup program to do some configurations.$ ibus-setup

All I changed was the keyboard shortcuts and input methods. For keyboard shortcuts, I was hoping Alt+Shift would just work but it didn't, so I changed it to Alt+Shift+space.

For input methods, I added Japanese - Anthy to enable Japanese input. You might have noticed that its icon is different from the default one. This is because I replaced its default icon with my own.

The configuration of ibus should be done now. You'll see a small EN icon in its systray. That confirms ibus is running now. Left click on the icon will show you the list available input methods, in this case, English and Japanese - Anthy.

.bashrc:

We need to tell the system that we are using ibus for alternate language inputs after logging out or shutdown. To do this, we update .bashrc and add some environment variables.$ nvim ~/.bashrc ----------------------------------------- ... export GTK_IM_MODULE=ibus export XMODIFIERS=@im=ibus export QT_IM_MODULE=ibus ...

i3/config:

Now, we need to start ibus each time we log into i3 window manager. To do this, we add ibus-autostart to at the end of i3's config file.$ nvim ~/.config/i3/config ----------------------------------------- ... exec --no-startup-id ibus-autostart

Japanese input is enabled and available for terminal as well.

Changing Default Anthy Icon:

I thought the default Anthy icon was not pretty and didn't like it. So, I decided to change it to my own. After searching for the icon in the system, I found it in /usr/share/ibus-anthy/icons/. It's called ibus-anthy.png. I used GIMP to create another icon and replaced it.

That's all!
-gibb

Building My Work Environment (Part 5)

Part 5 - Show Me Japanese in my Terminal

At this moment, any Japanese characters will show up as little rectangle shapes or some gibberish characters. This is, by default, because Slackware uses en_US as its locale. Locale is set using an environment variable, $LANG, and it is set in /etc/profile.d/lang.sh for system wide configuration.

I'd like to be able to read Japanese in terminals for myself, and don't need to apply this for the whole system. All I need to do is to export $LANG in .bashrc.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. This information below is solely used for my purpose and may not be suitable for others.

The locale for Japanese can be found by running the following command:$ locale -a | grep -i jp ja_JP.eucjp ja_JP.utf8

The Japanese locale for my system is jp_JP.utf8 (or jp_JP.UTF-8). To apply this in my environment, update .bashrc:$ nvim ~/.bashrc ----------------------------------------- export LANG=ja_JP.UTF-8

After this, either logout and back-in or source .bashrc will display Japanese characters properly in terminal.

However, this brings a bit of problem in my status bar. Time/date is displaying in Japanese as well. This is not what I wanted.

To fix this, I forced i3pystatus to use the en_US locale in its configuration file.$ nvim ~/.config/i3/i3pystatusconfig.py ----------------------------------------- from i3pystatus import Status import os # Setting LANG to en_US to avoid # showing dates in Japanese os.environ['LANG'] = 'en_US' ...

After saving the file, $Mod+Shift+r will change date/time in English.

In next article, let's talk about enabling Japanese input.

That's all!
-gibb

Building My Work Environment (Part 4)

Part 4 - De-Uglifying i3

There are many sites offer themes/themers for i3, like unix121's themer. But I like clean and simple, so I changed just a handful of components.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. This information below is solely used for my purpose and may not be suitable for others.

gtk2 Theme

I imported my old gtk2 theme, Morning Glory from Openbox days. This theme can be applied using lxappearance.$ tar -xzvf MorningGlory.tar.gz -C ~/.themes/ ... $ lxappearance

Icons

I still use Faenza icon set. I recently found out that this icon set can be downloaded and installed from slackbuilds.org


Font Awesome Fonts/Icons

i3pystatus I installed in the Part 3 uses icons to display each component, like CPU and memory. For that, font awesome needs to be installed. The latest version at the time of this writing is 5.0.10. Download a zip file, unzip it, and copy otf files from the use-on-desktop folder to system appropriate directory.$ unzip fontawesome-free-5.0.10.zip ... $ cd fontawesome-free-5.0.10/use-on-desktop/ # cp *.otf /usr/share/fonts/OTF # mkfontdir /usr/share/fonts/{TTF,OTF} # mkfontscale /usr/share/fonts/{TTF,OTF} # fc-cache -fv Restart X

To check if the fonts were properly installed, run fc-list:$ fc-list | grep -i awesome ...

Ricty Font

Ricty is Japanese True Type font based on Inconsolata and Circle M+ 1m, optimized for the programming usage. Here is some benefits of using the font:

  • Use Inconsolata for the Latin character glyphs and "Circle M+ 1m" font for other glyphs.
  • Adjust the width of full-width and normal-width character glyphs to 2:1 ratio exactly full and half.
  • Design the comma, period, colon, semicolon and bracket character glyphs to differentiate each other clearly to prevent confusions.
  • Design the high visibility p-sound sign attached Kana character glyphs.
  • Design the En-dash and Em-dash glyphs show them as the broken line to prevent input failures for LaTeX.
  • It shows Em-size space as "box" character because Em-size space often prevents debugging since users usually miss it. With Ricty Diminished font, users can find and fix it easily.

The instruction on how to build Ricty is from this site.

Bash Environment

I changed the style and color of PS1 in .bashrc. PS1='\[\e[38;5;106m\]\A \[\e[38;5;210m\]\u\[\e[38;5;229m\]@\[\e[38;5;220m\]\h\[\e[38;5;252m\][\[\e[38;5;69m\]\w\[\e[38;5;252m\]]\n\[\e[47m\]\[\e[38;5;232m\]$\[\e[00m\] '


=====
~/.bashrc
=====

Color Scheme for ranger

ranger is a text-based file manager with vi/vim key-bindings. Since it's key stroke based, it's perfect for i3. I like my default color scheme. But you can change the color scheme by ~/.config/ranger/colorschemes/.
For syntax highlighting in ranger, I use highlight.


=====
~/.config/ranger/*
=====

Color Scheme for urxvt

The color scheme for urxvt is controlled from .Xresources. I'm currently using gruvbox.

=====
~/.Xresources
=====

rofi

rofi is a window switcher, application launcher, and dmenu replacement, currently maintained by Dave Davenport. It's lightweight and highly customized. My rasi theme file, dark_elements.rasi, and rofi config file are availble.


=====
~/.config/rofi/*
=====

i3lock

I created a bash file to take a screenshot, blur that image, insert a lock icon, and apply it to i3lock.


=====
~/Scripts/i3lock/lock_blur_i3.sh
~/Scripts/i3lock/lock_red.png
=====

In next article, let's talk about displaying Japanese characters in terminal.

That's all!
-gibb

Building My Work Environment (Part 3)

Part 3 - Oh, what's that Window Manager?

Openbox used to be my de facto window manager for my systems for years. You can see some of my posts related to Openbox here. I have nothing but praises for its lightweight and solid performance (Not to mention it's highly customizable).

Then, I learned about Tiling window manager by chance. Tiling WM is designed to arrange windows in a way that they don't overlap each other. Also, it supports key-bindings to operate around keystrokes instead of using a mouse. That reminded me of vi/vim editor. Those facts piqued my interest.

I first started using Awesome Window Manager because it was a tiling window manger but also supported the floating option, which somewhat gave me a peace of mind. Awesome wm was highly configurable from a configuration file written in lua language. I quickly got around and configured it the way I wanted. However, a few months after, I noticed some keybindings stopped working and/or didn't behave the ways they should.

Then, I moved onto i3 window manager. It was next logical thing to try this wm as I read so many positive inputs about it. No regrets. It's easier to configure than Awesome wm because its configuration file is plain text, and it just worked. I've been using it a little more than a few months but I don't think I could go back to Awesome wm or stacking/floating window manager like Openbox ever again!

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. This information below is solely used for my purpose and may not be suitable for others.

Installation:

Installation of i3wm isn't that difficult with Slackware. Go to slackbuilds.org, download all dependencies, and install them one by one.... Installation of dependencies ... $ tar -xzvf i3.tar.gz i3/ i3/slack-desc i3/README i3/i3.SlackBuild i3/i3.info i3/doinst.sh i3/xinitrc.i3 $ mv i3-4.15.tar.bz2 i3/ # cd i3/ # ./i3.SlackBuild ... Slackware package /tmp/i3-4.15-x86_64-1_SBo.tgz created. # installpkg /tmp/i3-4.15-x86_64-1_SBo.tgz ... Executing install script for i3-4.15-x86_64-1_SBo.tgz. Package i3-4.15-x86_64-1_SBo.tgz installed.

At the beginning, I referred i3 like vi/vim. It's just like that. If you know right key combinations, your productivity would increase. But if you are not familiar with it, it's just so hard to deal with. In my humble opinion, although its learning curve is steep, it's worth learning how to properly use it.

To set i3 as your default windows manager, you'd need to run xwmconfig. $ xwmconfig

Config File:

i3's config file is located at ~/.config/i3/config, and it's a plain text file. It should be fairly easy to understand because of all the comments there. One thing you do need to remember is to reload the config file with $Mod+Shift+r each time the file has been modified.
=====
~/.config/i3/config
=====

Status Bar:

By default, i3 does not offer a status bar unless you install one. I tried with i3blocks and configured it with mpd/ncmpcpp support and everything I wanted to show in my status bar on my notebook with Debian stretch; however, to install i3blocks on Slackware, you need to go through ridiculous number of dependencies. For that reason, I gave up on installing i3blocks. Instead, I installed i3pystatus. i3pystatus was so easy to set up and manage it because each piece is a module, and it didn't take me long to configure it as I wanted.

Before i3pystatus can properly display, some python modules need to be installed: $ pip3 install --upgrade pip ... $ pip3 install netifaces \ > psutil \ > colour ... $

The i3pystatus version I downloaded from slackbuilds.org is 3.35. I'm not sure if this problem only applies to this version but when memory usage is displayed with {used_mem}, it displays a negative value. After reading up on different forums, I figured out that its source code for mem.py did not support newer version of psutil. Within the code, to get the value of used memory, it was subtracting cached and buffers values from used value. This was ok for psutil version before 4.4.0. With newer psutil (> 4.4.0), getting the used value itself was good enough, I guess.

To prove my point, this is what's going on: $ python3 >>> import psutil >>> psutil.__version__ '5.4.5' >>> mem = psutil.virtual_memory() svmem(total=...) >>> print(mem.used - mem.cached - mem.buffers) <== This is what's done in the code -311427072 <== Gives a negative value >>> print(mem.used) <== For newer psutil version, this is all you need 301985792

Now, we need to edit the source code to take care of newer version for psutil. 1) Change 2nd line from this:from psutil import virtual_memory to: import psutil 2) On line 45 and 46, there is a piece of code to get used memory. That should be changed from:memory_usage = virtual_memory() used = memory_usage.used - memory_usage.cached - memory_usage.buffers to:memory_usage = psutil.virtual_memory() if psutil.version_info < (4, 4, 0): used = memory_usage.used - memory_usage.cached - memory_usage.buffers else: used = memory_usage.used This should take care of displaying a negative value for used memory in i3pystatus.

=====
~/.config/i3/i3pystatusconf.py
=====

Screen Lock:

I use i3lock to lock the screen. It's simple and customizable.

Shutdown, Reboot, and Logout:

The official way of getting out of i3 is to press $Mod+Shift+e simultaneously. This will show a message bar on top of the screen. Then click on yes, exit i3 to exit. I found this step a bit cumbersome. I could type sudo /sbin/shutdown -h now in a terminal but I'd need to open one if I'm in say web browser workspace. So, I created a i3 mode to handle key combinations to logout, lock screen, reboot, or shutdown (referenced Arch Linux Wiki).

For this to work, sudoer needs to be enabled for a regular user to run the shutdown or reboot command.# visudo ------------------------ [user_name] ALL=NOPASSWD: /sbin/shutdown,/sbin/reboot

In next article, let's talk about changing the look and feel of i3 window manager.

That's all!
-gibb

Getting ‘heroku’ installed with Termux on Android

I have this personal project where I need to regularly update PostgreSQL database from a dump file so that users can view the most up-to-date information every week. My web hosting company, ICD Soft, offers MySQL but not PostgreSQL. I could convert a PostgreSQL dump to MySQL but doing this every time may be time consuming and there is a chance where someone who has no knowledge of database might need to handle this task if I'm not available, so converting was out of questions.

Another option was to look for a free service that offers managing a remote PostgreSQL server. Then, I found Heroku. It seems to offer what I want. So, I decided to give it a try.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. This information below is solely used for my purpose and may not be suitable for others.

As usual, I do most of developing work on my cell phone (Samsung Note 8), I tried to install heroku on Termux. Installation was fairly simple after tweeking a bit.

PHP Installation:

First thing first, I'll be using PHP to develop my site with heroku. So, PHP needs to be installed on Termux:$ apt-get update $ apt-get install php

Composer Installation:

Secondly, composer (PHP dependent management tool) needs to be installed:$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" $ php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" $ php composer-setup.php $ php -r "unlink('composer-setup.php');"

Standard Heroku Installation:

Now follow the instruction from Heroku documentation site with some tweeks for Termux: $ wget http://cli-assets.heroku.com/heroku-cli/channels/stable/heroku-cli-linux-x64.tar.gz -O heroku.tar.gz $ tar -xvzf heroku.tar.gz -C heroku $ mv heroku /data/data/com.termux/files/usr/lib/heroku $ ln -s /data/data/com.termux/files/usr/lib/heroku/bin/heroku /data/data/com.termux/files/usr/bin/heroku

Tweekings 1 - heroku script:

Installation of Heroku is now done, but it doesn't work as is because I just installed Linux version of tarball in Termux on Android. If heroku is executed now, it'll give you some error messages:$ heroku bash: /data/data/com.termux/files/usr/bin/heroku: /usr/bin/env: bad interpreter: No such file or directory

This is because the heroku script is pointing to /usr/bin/env for bash. This needs to be changed to correct path for Termux:$ cd /data/data/com.termux/files/usr/lib/heroku/bin/ $ vim heroku #!/usr/bin/env bash set -e ... Change the first line from #!/usr/bin/env bash to #!/data/data/com.termux/files/usr/bin/env bash, and save the file.

Tweekings 2 - node binary:

The tarball downloaded contains node.js binary for auto update but this binary doesn't seem to work in Termux and it would give an Exec format error:$ heroku /data/data/com.termux/files/usr/bin/heroku: line 29: /data/data/com.termux/files/usr/lib/heroku/bin/node: cannot execute binary file: Exec format error

To work around this problem, I installed node.js separately and made a symlink. This seemed working and no more Exec format error:$ apt-get install nodejs ... $ cd /data/data/com.termux/files/usr/lib/heroku/bin $ mv node node.old $ ln -s ../../../bin/node node $ heroku --version heroku-cli/6.15.31-958455a (android-arm64) node-v8.10.0 $ heroku login Enter your Heroku credentials: Email: *** Password: *** Logged in as *** $

voilĂ , logged in successfully.

That's all!
-gibb