diff --git a/_includes/prj_scr.html b/_includes/prj_scr.html index e6d5abc..a2e9cda 100644 --- a/_includes/prj_scr.html +++ b/_includes/prj_scr.html @@ -1,8 +1,8 @@
{% if page.category == "ru" %} - + {% else %} - + {% endif %} {{ scrname }}
diff --git a/_posts/2014-01-14-about-zshrc.html b/_posts/2014-01-14-about-zshrc.html index ab34b1d..603b3be 100644 --- a/_posts/2014-01-14-about-zshrc.html +++ b/_posts/2014-01-14-about-zshrc.html @@ -6,19 +6,22 @@ hasTr: true tags: zshrc, configuration, linux title: About zshrc short: about-zshrc -description: It is first paper in my blog (I think I need something here for tests =)). There are many similar articles, and I'll not be an exception. I just want to show my .zshrc and explain what it does and why it is needed. Also any comments or additions are welcome. It is a translated paper from Russian (original). +description: It is first paper in my blog (I think I need something here for tests =)). There are many similar articles, and I'll not be an exception. I just want to show my .zshrc and explain what it does and why it is needed. Also any comments or additions are welcome. It is a translated paper from Russian (original). --- -

Prepare

+

Prepare

First install recommended minima:

+ {% highlight bash %} pacman -Sy pkgfile zsh zsh-completions zsh-syntax-highlighting {% endhighlight %} -

pkgfile is a very useful utility. Also this command will install shell, additional completion and syntax highlighting.

-

Shell configuration

-

All options are avaible here.

+

pkgfile is a very useful utility. Also this command will install shell, additional completion and syntax highlighting.

+ +

Shell configuration

+

All options are avaible here.

Set history file and number of commands in cache of the current session and in the history file:

+ {% highlight bash %} # history HISTFILE=~/.zsh_history @@ -27,6 +30,7 @@ SAVEHIST=500000 {% endhighlight %}

I can not remember all Ctrl+ combinations so I bind keys to its default usages:

+ {% highlight bash %} # bindkeys bindkey '^[[A' up-line-or-search # up arrow for back-history-search @@ -38,9 +42,11 @@ bindkey '\e[4~' end-of-line # end bindkey '\e[5~' up-line-or-history # page-up bindkey '\e[6~' down-line-or-history # page-down {% endhighlight %} +

But in this case Up/Down arrows are used to navigate through the history based on already entered part of a command. And PgUp/PgDown will ignore already entered part of a command.

Command autocomplete:

+ {% highlight bash %} # autocomplete autoload -U compinit @@ -48,9 +54,11 @@ compinit zstyle ':completion:*' insert-tab false zstyle ':completion:*' max-errors 2 {% endhighlight %} +

Full command autocomplete will be enabled. insert-tab false will enable autocomplete for non-entered commands. max-errors sets maximum number of errors that could be corrected.

Prompt:

+ {% highlight bash %} # promptinit autoload -U promptinit @@ -58,6 +66,7 @@ promptinit {% endhighlight %}

Enable colors:

+ {% highlight bash %} # colors autoload -U colors @@ -66,53 +75,71 @@ colors

Here are some other options.

Change directory without cd:

+ {% highlight bash %} # autocd setopt autocd {% endhighlight %} +

Correcting of typos (and question template):

+ {% highlight bash %} # correct setopt CORRECT_ALL SPROMPT="Correct '%R' to '%r' ? ([Y]es/[N]o/[E]dit/[A]bort) " {% endhighlight %} +

Disable f#$%ing beep:

+ {% highlight bash %} # disable beeps unsetopt beep {% endhighlight %} +

Enable calculator:

+ {% highlight bash %} # calc autoload zcalc {% endhighlight %} +

Append history (do not recreate the history file):

+ {% highlight bash %} # append history setopt APPEND_HISTORY {% endhighlight %} +

Do not save dups to history file:

+ {% highlight bash %} # ignore spaces in history setopt HIST_IGNORE_ALL_DUPS {% endhighlight %} +

...and additional spaces:

+ {% highlight bash %} # ignore dups in history setopt HIST_IGNORE_SPACE {% endhighlight %} +

...and blank lines too:

+ {% highlight bash %} # reduce blanks in history setopt HIST_REDUCE_BLANKS {% endhighlight %} +

Enable pkgfile:

+ {% highlight bash %} # pkgfile source /usr/share/doc/pkgfile/command-not-found.zsh {% endhighlight %} -

Syntax highlighting

+

Syntax highlighting

+ {% highlight bash %} # highlighting source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh @@ -159,10 +186,12 @@ ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=yellow' # root example #ZSH_HIGHLIGHT_STYLES[root]='bg=red' {% endhighlight %} +

In first line highlighting is turned on. Next main, brackets and pattern highlighting are turned on. Patterns are set below (rm -rf * in the example). Also root and cursor highlighting may be turned on. Colors syntax is understandable, fg is font color, bg is background color.

-

$PROMPT and $RPROMPT

+

$PROMPT and $RPROMPT

The general idea is the use single .zshrc for root and normal user:

+ {% highlight bash %} # PROMPT && RPROMPT if [[ $EUID == 0 ]]; then @@ -185,6 +214,7 @@ fi {% endhighlight %}

fg is font color, bg is background color. _bold and _no_bold regulate the tint. Commands should be in %{ ... %} so they do not appear. Avaible colors are:

+ {% highlight bash %} black red @@ -197,6 +227,7 @@ white {% endhighlight %}

Avaible variables are:

+ {% highlight bash %} %n - the username %m - the computer's hostname (truncated to the first period) @@ -213,6 +244,7 @@ white {% endhighlight %}

RPROMPT (acpi package is necessary):

+ {% highlight bash %} precmd () { # battery charge @@ -237,12 +269,14 @@ $(batcharge)\ $returncode\ "%{$fg_bold[white]%}]%{$reset_color%}" {% endhighlight %} +

My RPROMPT shows current time, battery change and last returned code. precmd() is necessary for automatic updating. The construct $(if.true.false) is conditional statement in zsh.

-

Aliases

+

Aliases

Copy only those aliases that you need. If any alias uses application that is not installed it will leads to fail of loading of configuration file.

Small useful (or maybe not) function:

+ {% highlight bash %} show_which() { OUTPUT=$(which $1 | cut -d " " -f7-) @@ -251,6 +285,7 @@ show_which() { {% endhighlight %}

Here is the first group of aliases:

+ {% highlight bash %} ## alias # colored grep @@ -269,7 +304,8 @@ alias less='vimpager' alias zless='vimpager' {% endhighlight %} -

Here are ls aliases (see man ls):

+

Here are ls aliases (see man ls):

+ {% highlight bash %} alias ls='show_which ls && ls --color=auto --group-directories-first' alias ll='show_which ll && ls -l --human-readable' @@ -282,6 +318,7 @@ alias lm='show_which lm && la | more' {% endhighlight %}

Here are aliases to quick file view from console (just type a file name!):

+ {% highlight bash %} # alias -s alias -s {avi,mpeg,mpg,mov,m2v,mkv}=mpv @@ -293,6 +330,7 @@ alias -s {html,htm}=opera {% endhighlight %}

Here are "sudo" aliases:

+ {% highlight bash %} # sudo alias if [[ $EUID == 0 ]]; then @@ -316,6 +354,7 @@ fi {% endhighlight %}

Here are global aliases. If they are enable the command cat foo g bar will be equivalent the command cat foo | grep bar:

+ {% highlight bash %} # global alias alias -g g="| grep" @@ -325,7 +364,7 @@ alias -g h="| head" alias -g dn="&> /dev/null &" {% endhighlight %} -

Functions

+

Functions

Here is a special function for xrandr:

{% highlight bash %} @@ -352,6 +391,7 @@ projctl () { {% endhighlight %}

Unfortunately I can not remember tar flags thus I use special functions:

+ {% highlight bash %} # function to extract archives # EXAMPLE: unpack file @@ -405,6 +445,7 @@ pack () { {% endhighlight %}

Here is a special function for su:

+ {% highlight bash %} su () { CHECKSU=0 @@ -423,6 +464,7 @@ su () { {% endhighlight %}

Function that replaces original rm command. If you type rm it will be equivalent moving to trash an you can easily restore a file:

+ {% highlight bash %} rm () { # error check @@ -466,6 +508,7 @@ rm () { {% endhighlight %}

Functions with automatic rehash after installing/removing packages are:

+ {% highlight bash %} pacman () { /usr/bin/sudo /usr/bin/pacman $* && echo "$*" | grep -q "S\|R\|U" && rehash @@ -478,12 +521,14 @@ yatest () { /usr/bin/yaourt --config /etc/pactest.conf $* && echo "$*" | grep -q "S\|R\|U" && rehash } {% endhighlight %} -

But autocomplete for yaourt -Ss will require root privileges.

-

Variables

+

But autocomplete for yaourt -Ss will require root privileges.

+ +

Variables

It is recommended to set own variables in ~/.zshenv. But I have everything stored in the single file.

Here are path, mask of new files, editor and pager:

+ {% highlight bash %} # path export PATH="$PATH:$HOME/.local/bin" @@ -495,6 +540,7 @@ export PAGER="vimpager" {% endhighlight %}

Here is hashes. If they are enable the command ~global will be equivalent the command /mnt/global:

+ {% highlight bash %} # hash hash -d global=/mnt/global @@ -504,8 +550,12 @@ hash -d u1=/mnt/usbdev1 hash -d u2=/mnt/usbdev {% endhighlight %} -

Screenshot

-

+

Screenshot

+

+ {% assign scrdesc = "Zsh demonstation" %} + {% assign scrname = "zshrc_demo" %} + {% include prj_scr.html %} +

-

File

-

Here is my .zshrc.

+

File

+

Here is my .zshrc.

diff --git a/_posts/2014-01-21-building-qutim-using-qt5.html b/_posts/2014-01-21-building-qutim-using-qt5.html index a570e60..441a90a 100644 --- a/_posts/2014-01-21-building-qutim-using-qt5.html +++ b/_posts/2014-01-21-building-qutim-using-qt5.html @@ -6,30 +6,36 @@ hasTr: true tags: archlinux, linux, building, qutim title: Building Qutim using Qt5 short: building-qutim-using-qt5 -description: Qutim is a multiprotocol and cross platform messenger. It is written on CPP using Qt library. The project is actively developed. In this paper I will say about building this package in Archlinux using Qt5 library (instead of Qt4 which is used in current AUR packages). +description: Qutim is a multiprotocol and cross platform messenger. It is written on CPP using Qt library. The project is actively developed. In this paper I will say about building this package in Archlinux using Qt5 library (instead of Qt4 which is used in current AUR packages). --- -

What's wrong?

-

This package uses qbs for building, which is a bit strange IMHO. A package, which is necessary for building, is in AUR . I recommend to use git version of the package. When I asked Andrea Scarpino (who maintains KDE and Qt packages into the official repos) about qbs, he told me "we will support it in time". And I agree with him, the project seems to be a little unstable.

+

What's wrong?

+

This package uses qbs for building, which is a bit strange IMHO. A package, which is necessary for building, is in AUR . I recommend to use git version of the package. When I asked Andrea Scarpino (who maintains KDE and Qt packages into the official repos) about qbs, he told me "we will support it in time". And I agree with him, the project seems to be a little unstable.

-

Prepare

+

Prepare

Install dependences. I had used namcap, so maybe I missed something:

+ {% highlight bash %} pacman -Sy --asdeps clang git libc++abi qt5-quick1 qt5-x11extras yaourt -S --asdeps jreen-git qbs-git {% endhighlight %} -

qbs settings

-

You may read about qbs on the link or see examples which are provides by the package. qbs uses configuration file that firstly you must create and secondly it is stored in your home directory. In theory a configuration file creating ((~/.config/QtProject/qbs.conf)) looks like this:

+

qbs settings

+

You may read about qbs on the link or see examples which are provides by the package. qbs uses configuration file that firstly you must create and secondly it is stored in your home directory. In theory a configuration file creating ((~/.config/QtProject/qbs.conf)) looks like this:

+ {% highlight bash %} qbs-setup-qt --detect qbs-detect-toolchains {% endhighlight %} +

Firstly we find Qt libraries. Then we find toolchains (such as compilers). And next we must insert a toolchain into Qt profile (for example, we need clang toolchain):

+ {% highlight bash %} sed 's/clang\\/qt-5-2-0\\/g' -i ~/.config/QtProject/qbs.conf {% endhighlight %} +

And there are other ways. You may edit the file manually or use qbs-config-ui or qbs-config.

So, we have created the configuration file and put it into build directory:

+ {% highlight ini %} [General] @@ -65,10 +71,12 @@ qutim\qbs\architecture=x86_64 qutim\qbs\endianness=little qutim\qbs\toolchain=clang, llvm, gcc {% endhighlight %} -

qbs-qutim.conf

-

Patch for sources

+

qbs-qutim.conf

+ +

Patch for sources

The first problem is clang (at least in Archlinux):

+ {% highlight diff %} diff -ruN qutim.orig/core/libqutim.qbs qutim/core/libqutim.qbs --- qutim.orig/core/libqutim.qbs 2014-01-06 15:39:56.000000000 +0400 @@ -83,7 +91,9 @@ diff -ruN qutim.orig/core/libqutim.qbs qutim/core/libqutim.qbs } {% endhighlight %} +

And the second one is Vk plugin:

+ {% highlight diff %} diff -ruN qutim.orig/protocols/vkontakte/vreen/vreen.qbs qutim/protocols/vkontakte/vreen/vreen.qbs --- qutim.orig/protocols/vkontakte/vreen/vreen.qbs 2014-01-06 15:41:42.000000000 +0400 @@ -97,9 +107,11 @@ diff -ruN qutim.orig/protocols/vkontakte/vreen/vreen.qbs qutim/protocols/vkontak property string vreen_version_major: 1 property string vreen_version_minor: 9 {% endhighlight %} -

qutim-qbs-1.1.patch

-

Get sources

+

qutim-qbs-1.1.patch

+ +

Get sources

+ {% highlight bash %} # clone repo git clone https://github.com/euroelessar/qutim @@ -116,20 +128,25 @@ cd .. patch -p0 -i qutim-qbs-1.1.patch {% endhighlight %} -

Building

+

Building

+ {% highlight bash %} cd qutim HOME=$(pwd) qbs -j $(nproc) -d ../build release profile:qutim {% endhighlight %} +

I want to create a universal recipe for the building, thus we must set $HOME directory. Flag -j means number of jobs, -d means build directory, release means building type (debug, release), profile is used profile, which is described in the configuration file.

-

Installation

+

Installation

+ {% highlight bash %} HOME=$(pwd) sudo qbs install -d ../build --install-root "/usr" profile:qutim {% endhighlight %} +

We must set root directory (--install-root), because without this option the package will be installed into / (/bin and /lib).

-

PKGBUILD

+

PKGBUILD

+ {% highlight bash %} pkgname=qutim-qt5-git _gitname=qutim @@ -182,4 +199,5 @@ package() { HOME="${srcdir}" qbs install -d ../build --install-root "${pkgdir}/usr" profile:qutim } {% endhighlight %} -

PKGBUILD

+ +

PKGBUILD

diff --git a/_posts/2014-03-06-site-changes.html b/_posts/2014-03-06-site-changes.html index c4a6245..77ec6c4 100644 --- a/_posts/2014-03-06-site-changes.html +++ b/_posts/2014-03-06-site-changes.html @@ -8,16 +8,19 @@ title: Site changes short: site-changes description: I decided to change my site. You may find short list of changes below. --- -

The list of changes:

+

The list of changes:

diff --git a/_posts/2014-03-23-creating-custom-repo.html b/_posts/2014-03-23-creating-custom-repo.html index 771086c..cbd71e4 100644 --- a/_posts/2014-03-23-creating-custom-repo.html +++ b/_posts/2014-03-23-creating-custom-repo.html @@ -8,13 +8,17 @@ title: Creating own repository short: creating-custom-repo description: It is a short paper devoted to creation own ArchLinux repository. --- -

Prepare

+

Prepare

First find a server and desire to have sex with it. It is recommended to use Archlinux on it, but it is not necessarily - because you may create special root for Archlinux. Also you need two packages, devtools and pacman:

+ {% highlight bash %} pacman -Sy devtools {% endhighlight %} -

devtools is script set for building automation in the clean chroot. I think most of Arch maintainers use it.

+ +

devtools is script set for building automation in the clean chroot. I think most of Arch maintainers use it.

+

Let's create working directories and set colors:

+ {% highlight bash %} # colors if [ ${USECOLOR} == "yes" ]; then @@ -50,10 +54,11 @@ if [ ! -d "${STAGINGDIR}" ]; then mkdir -p "${STAGINGDIR}" || error_mes "unknown" fi {% endhighlight %} +

${REPODIR}/{i686,x86_64} are directories for repository, ${PREPAREDIR} is directory where compiled packages will be stored, ${STAGINGDIR} is one where packages will be built.

-

A bit of theory

-

Create directory, share it (using ftp, for example). It has two subdirectories - i686 and x86_64 - for each architecture respectively. And fill them with a set of packages.

+

A bit of theory

+

Create directory, share it (using ftp, for example). It has two subdirectories - i686 and x86_64 - for each architecture respectively. And fill them with a set of packages.

Updating repository may be split into the following steps:

  1. Creating PKGBUILDs (or updating them from AUR).
  2. @@ -68,15 +73,17 @@ fi
  3. Cleaning.
-

Creating PKGBUILDs

+

Creating PKGBUILDs

Download source tarballs from AUR:

+ {% highlight bash %} cd "${STAGINGDIR}" yaourt -G package-name {% endhighlight %} -

Packages building

+

Packages building

Build each package automatically:

+ {% highlight bash %} func_build() { if [ ${USECOLOR} == "yes" ]; then @@ -114,14 +121,17 @@ echo -e "${bwhite}[II]${cclose} Building packages" cd "${STAGINGDIR}" /usr/bin/find -name 'PKGBUILD' -type f -execdir /usr/bin/bash -c "func_build "${PREPAREDIR}" "${ROOTDIR}"" \; {% endhighlight %} +

It is recommended to add the following lines to /etc/sudoers:

+ {% highlight bash %} username ALL=NOPASSWD: /usr/bin/staging-i686-build username ALL=NOPASSWD: /usr/bin/staging-x86_64-build username ALL=NOPASSWD: /usr/bin/multilib-staging-build {% endhighlight %} -

Packages signing

+

Packages signing

+ {% highlight bash %} # signing if [ ${USEGPG} == "yes" ]; then @@ -132,9 +142,11 @@ if [ ${USEGPG} == "yes" ]; then done fi {% endhighlight %} -

It is recommended to configure gpg-agent.

-

Creating the list of packages

+

It is recommended to configure gpg-agent.

+ +

Creating the list of packages

+ {% highlight bash %} # creating packages list cd "${PREPAREDIR}" @@ -144,15 +156,18 @@ echo -e "${bwhite}[II] ${bblue}=>${cclose} i686 packages: \n${bwhite}${i686_PACK echo -e "${bwhite}[II] ${bblue}=>${cclose} x86_64 packages: \n${bwhite}${x86_64_PACKAGES}${cclose}" {% endhighlight %} -

Repository update

+

Repository update

Here is a function for removal packages from database and repository:

+ {% highlight bash %} func_remove() { _PACKAGE="$1" /usr/bin/rm -f "${_PACKAGE}"{,.sig} } {% endhighlight %} +

i686 repository update:

+ {% highlight bash %} # updating i686 repo echo -e "${bwhite}[II]${cclose} Updating ${bwhite}i686${cclose} repo" @@ -169,7 +184,9 @@ for PACKAGE in ${i686_PACKAGES}; do /usr/bin/repo-add --files ${DBNAME}.files.tar.gz "${PACKAGE}" done {% endhighlight %} +

x86_64 repository update:

+ {% highlight bash %} # updating x86_64 repo echo -e "${bwhite}[II]${cclose} Updating ${bwhite}x86_64${cclose} repo" @@ -187,7 +204,8 @@ for PACKAGE in ${x86_64_PACKAGES}; do done {% endhighlight %} -

Cleaning

+

Cleaning

+ {% highlight bash %} # clear cd "${PREPAREDIR}" @@ -196,8 +214,9 @@ cd "${STAGINGDIR}" /usr/bin/rm -rf * {% endhighlight %} -

Creating symlinks

+

Creating symlinks

You may want to create a directory, which will contain symlinks on actual packages with names, which does not contain version:

+ {% highlight bash %} # creating symlinks if [ ${SYMLINK} == "yes" ]; then @@ -219,11 +238,12 @@ if [ ${SYMLINK} == "yes" ]; then fi {% endhighlight %} -

File

-

Here is the scripts. Download source tarballs and run script (editing variables if it is necessary).

+

File

+

Here is the scripts. Download source tarballs and run script (editing variables if it is necessary).

-

Repository usage

+

Repository usage

Just add following lines to /etc/pacman.conf:

+ {% highlight bash %} [$REPONAME] Server = ftp://$REPOADDRESS/repo/$arch diff --git a/_posts/2014-04-18-loveless.html b/_posts/2014-04-18-loveless.html index d8133fc..aa0f565 100644 --- a/_posts/2014-04-18-loveless.html +++ b/_posts/2014-04-18-loveless.html @@ -8,25 +8,24 @@ title: Loveless short: loveless description: Here is a small poem from Final Fantasy VII Crisis Core. --- -

Prologue

-

-When the war of the beasts brings about the world's end
+

Prologue

+

When the war of the beasts brings about the world's end
The goddess descends from the sky
Wings of light and dark spread afar
She guides us to bliss, her gift everlasting.

-

Act I

+

Act I

Infinite in mystery is the gift of the Goddess
We seek it thus, and take to the sky
Ripples form on the water's surface
The wandering soul knows no rest.

-

Act II

+

Act II

There is no hate, only joy
For you are beloved by the goddess
Hero of the dawn, Healer of worlds
Dreams of the morrow hath the shattered soul
Pride is lost
Wings stripped away, the end is nigh.

-

Act III

+

Act III

My friend, do you fly away now?
To a world that abhors you and I?
All that awaits you is a somber morrow
@@ -35,7 +34,7 @@ My friend, your desire
Is the bringer of life, the gift of the goddess
Even if the morrow is barren of promises
Nothing shall forestall my return.

-

Act IV

+

Act IV

My friend, the fates are cruel
There are no dreams, no honor remains
The arrow has left, the bow of the goddess
@@ -46,7 +45,7 @@ And your eternal slumber
Legend shall speak
Of sacrifice at world's end
The wind sails over the water's surface.

-

Act V

+

Act V

Even if the morrow is barren of promises
Nothing shall forestall my return
To become the dew that quenches the land
diff --git a/_posts/2014-05-07-my-desktop.html b/_posts/2014-05-07-my-desktop.html index f909edb..64cd1fd 100644 --- a/_posts/2014-05-07-my-desktop.html +++ b/_posts/2014-05-07-my-desktop.html @@ -8,53 +8,59 @@ title: Apps which I use short: my-desktop description: Here is a short paper devoted to the set of applications and extensions that I use everyday on my home computer. --- -

Applications

+

Applications

-

KDE settings

-

Here is a screenshot:
-

+

KDE settings

+

+ {% assign scrdesc = "KDE screenshot" %} + {% assign scrname = "kde" %} + {% include prj_scr.html %} +

-

QtCurve is used as Qt style, its settings may be found here, window decorations are presented by QtCurve too. Cursor theme is ecliz-small. Plasma theme is volatile. Icon pack is compass. I use fonts which are based on Liberation.

+

QtCurve is used as Qt style, its settings may be found here, window decorations are presented by QtCurve too. Cursor theme is ecliz-small. Plasma theme is volatile. Icon pack is compass. I use fonts which are based on Liberation.

-

Used widgets (from left to right, top to bottom) are: menubar, homerun with transparent icon, icontask, netctl, default KDE tray, colibri for notifications, pytextmonitor.

+

Used widgets (from left to right, top to bottom) are: menubar, homerun with transparent icon, icontask, netctl, default KDE tray, colibri for notifications, pytextmonitor.

-

As a bonus material here is a settings for konsole bright colors:
-

+

As a bonus material here is a settings for konsole bright colors.

+

+ {% assign scrdesc = "Zsh demonstation" %} + {% assign scrname = "zshrc_demo" %} + {% include prj_scr.html %} +

- -

Firefox settings

+

Firefox settings

I do not use a special settings, thus I get you a list of used add-ons:

-

The file pattern

+

The file pattern

It must be specified in the header that it is a completion file and application for which it will complete (may be string if this file provides completions for several applications): {% highlight bash %} @@ -65,9 +65,10 @@ case "$service" in ;; esac {% endhighlight %} +

-

Flags

+

Flags

As it was said above, there are some different ways to create these files. In particular they differ in the flag declaration and their further processing. In my case I will use _arguments command, which require a specific format of variables: FLAG[description]:MESSAGE:ACTION. The last two fields are not required and, as you will see below, are not needed in some cases. If you want to add two flags for an action (short and long format), then the format is a little bit complicated: {(FLAG_2)FLAG_1,(FLAG_1)FLAG_2}[description]:MESSAGE:ACTION. It should be noted that if you want to create completions for two flags but some flags have not a second format. you will should to add following line: {FLAG,FLAG}[description]:MESSAGE:ACTION. MESSAGE is a message which will be shown, ACTION is an action which will be performed after this flag. In this tutorial ACTION will be following: ->STATE.

So, according to our requirements, flags declaration will be following: @@ -82,9 +83,10 @@ _netctl_gui_arglist=( {'--set-opts','--set-opts'}'[set options for this run, comma separated]:comma separated:->settings' ) {% endhighlight %} +

-

Arrays of variables

+

Arrays of variables

In my case there are two static arrays (which will not be changed): {% highlight bash %} @@ -106,9 +108,10 @@ _netctl_profiles() { print $(find /etc/netctl -maxdepth 1 -type f -printf "%f\n") } {% endhighlight %} +

-

Function

+

Function

Remember, there was something about a state above? It is stored in the variable $state and in this function we will check what it is to choose the appropriate action. At the beginning of the function we should call _arguments with our flags. {% highlight bash %} @@ -140,9 +143,10 @@ _netctl-gui() { esac } {% endhighlight %} +

-

Conclusion

-

File should be places to /usr/share/zsh/site-functions/ with any name (it is recommended to set prefix to _). You may found the example in my repository.

+

Conclusion

+

File should be places to /usr/share/zsh/site-functions/ with any name (it is recommended to set prefix to _). You may found the example in my repository.

-

The additional information may be found in zsh-completions repository. For example there is this How-To. And also there are a lot of examples.

+

The additional information may be found in zsh-completions repository. For example there is this How-To. And also there are a lot of examples.

diff --git a/_posts/2014-07-17-writting-own-completions-p2.html b/_posts/2014-07-17-writting-own-completions-p2.html index f5354a8..decb1a1 100644 --- a/_posts/2014-07-17-writting-own-completions-p2.html +++ b/_posts/2014-07-17-writting-own-completions-p2.html @@ -6,13 +6,13 @@ layout: paper tags: linux, development title: Writting own Shell completions. Bash short: writting-own-completions-p2 -description: Some basics of creating a completion files for own application are described in these articles. +description:
bash_completion
Some basics of creating a completion files for own application are described in these articles. --- -

Preamble

-

While developing one of my projects I have wanted to add completion files. I have already tried to create these files, but I was too lazy to read some manuals about it.

+

Preamble

+

While developing one of my projects I have wanted to add completion files. I have already tried to create these files, but I was too lazy to read some manuals about it.

-

Introduction

-

Bash, unlike zsh, demands some dirty workarounds for completions. Cursory have Googled, I have not found a more or less normal tutorials, so it is based on the available pacman completion files in my system.

+

Introduction

+

Bash, unlike zsh, demands some dirty workarounds for completions. Cursory have Googled, I have not found a more or less normal tutorials, so it is based on the available pacman completion files in my system.

Lets consider the example of the same my application. I remind you that a part of help message is as follows:

@@ -32,7 +32,7 @@ netctl-gui [ -h | --help ] [ -e ESSID | --essid ESSID ] [ -с FILE | --config FI

-

The file pattern

+

The file pattern

Here all variables must return an array. And there no specific formats. First we declare the flags and then we describe all other variables. As I am not going to describe the functions in more detail below I remind you that _netctl_profiles() should be generated each time: {% highlight bash %} @@ -55,9 +55,10 @@ And finally again without isolation in a separate function we create a de {% highlight bash %} complete -F _netctl_gui netctl-gui {% endhighlight %} +

-

Flags

+

Flags

As it was said above there is no specific format, so all available flags declare by array: {% highlight bash %} @@ -75,9 +76,10 @@ _netctl_gui_arglist=( '--set-opts' ) {% endhighlight %} +

-

Arrays of variables

+

Arrays of variables

I just give a function that looked like this in zsh: {% highlight bash %} @@ -93,9 +95,10 @@ _netctl_profiles() { echo $(find /etc/netctl -maxdepth 1 -type f -printf "%f\n") } {% endhighlight %} +

-

Function

+

Function

The variable COMPREPLY responds for completion in Bash. To keep track of the current state function _get_comp_words_by_ref must be called with parameters cur (current flag) and prev (previous flag, it is the state). Also some point for case are needed (variables want*). Function compgen is used for completion generation. A list of words is given after flag -W. (Also there is flag -F which requires a function as argument, but it gives warning for me.) The last argument is a current string to which you want to generate completion.

So, here is our function: @@ -134,7 +137,8 @@ _netctl_gui() { true } {% endhighlight %} +

-

Conclusion

-

File should be places to /usr/share/bash-completion/completions/ with any name. You may found the example in my repository.

+

Conclusion

+

File should be places to /usr/share/bash-completion/completions/ with any name. You may found the example in my repository.

diff --git a/about.html b/about.html index 6869755..e86acb6 100644 --- a/about.html +++ b/about.html @@ -38,7 +38,7 @@ GS/CS d-(+) s: a-- C++++ UL+++>$ P L++ E--- W++ N !o !K w- !O M- !V PS+@ PE Y PG {% endhighlight %}
- + Photo
Photo by Grineva O.V.
@@ -63,7 +63,7 @@ GS/CS d-(+) s: a-- C++++ UL+++>$ P L++ E--- W++ N !o !K w- !O M- !V PS+@ PE Y PG
The Trusted User (TU) is a member of the community charged with keeping the AUR in working order. He/she maintains popular packages (communicating with and sending patches upstream as needed), and votes in administrative matters. A TU is elected from active community members by current TUs in a democratic process. TUs are the only members who have a final say in the direction of the AUR.
-

+

© ArchWiki