<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>hwde</title><link href="https://www.hergenhahn-web.de/" rel="alternate"></link><link href="https://www.hergenhahn-web.de/feeds/all.atom.xml" rel="self"></link><id>https://www.hergenhahn-web.de/</id><updated>2024-07-05T00:00:00+02:00</updated><subtitle>a personal webpage and a technical blog</subtitle><entry><title>How to show files and contents of a directory in nvim-telescope if it is in .gitignore</title><link href="https://www.hergenhahn-web.de/telescope-gitignore.html" rel="alternate"></link><published>2024-07-05T00:00:00+02:00</published><updated>2024-07-05T00:00:00+02:00</updated><author><name>Sven Hergenhahn</name></author><id>tag:www.hergenhahn-web.de,2024-07-05:/telescope-gitignore.html</id><summary type="html">&lt;p class="first last"&gt;How to show files and contents of a directory in nvim-telescope if it is in .gitignore&lt;/p&gt;
</summary><content type="html">&lt;p&gt;The usecase is pretty simple here: I'm heavily using gitlab-ci job templates in
various gitlab projects by using the include statement.&lt;/p&gt;
&lt;p&gt;While this greatly reduces code duplication, it opens up for another problem:
Many IDEs (neovim - well, telescope - among them) by default ignore
files/directories present in .gitignore. This makes perfectly sense in most
cases and is not somethin I'd like to generally switch off (even though it is
easil possible).&lt;/p&gt;
&lt;p&gt;But my idea here is different though: I'd like to provide the content of the
gitlab-templastes project as a symlink in other projects to make the files
searchable for telescope. At the same time I do not want to accidentially
commit them to any project.&lt;/p&gt;
&lt;p&gt;So, I do&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;ln&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;/path/to/gitlab-templates
&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;gitlab-templates&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;.gitignore
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;So far so good, doing a git status does not show the symlink, but the files
also do not show up in telescope (where I would like to make them searchable
etc.)&lt;/p&gt;
&lt;p&gt;The solution is pretty simple: In my case, telescope uses fzf and fd under the
hood to search for files. Both support themselves the usage of the file
~/.ignore. This file can be used to provide a list of files and directories
that should be ignored by the search. This does not yet help as we are trying to un-ignore files here, so now comes the trick:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;The .ignore files precedes over .gitignore&lt;/li&gt;
&lt;li&gt;The .ignore file can also contain negated rules.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Any rule that starts with an exclamation mark will explicitely unignore the pattern (same as in .gitignore files).&lt;/p&gt;
&lt;p&gt;Thus, adding the following line to ~/.ignore will make the files under the symlinked directory &lt;em&gt;gitlab-templates&lt;/em&gt; searchable in telescope, because they will not be ignored by fd:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;cat&lt;span class="w"&gt; &lt;/span&gt;~/.ignore
!gitlab-templates
.git/
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;On the other hand, git will still ignore the files, so no need to worry about accidentially committing them.&lt;/p&gt;
&lt;p&gt;Problem solved.&lt;/p&gt;
</content><category term="howto"></category><category term="fd"></category><category term="fzf"></category><category term="git"></category><category term="ignore"></category><category term="nvim"></category><category term="telescope"></category><category term="vim"></category></entry><entry><title>Create regular Valheim backups automatically</title><link href="https://www.hergenhahn-web.de/valheim_backup.html" rel="alternate"></link><published>2021-04-23T11:06:00+02:00</published><updated>2021-04-23T11:06:00+02:00</updated><author><name>Sven Hergenhahn</name></author><id>tag:www.hergenhahn-web.de,2021-04-23:/valheim_backup.html</id><summary type="html">&lt;p class="first last"&gt;... with a python script&lt;/p&gt;
</summary><content type="html">&lt;div class="section" id="why"&gt;
&lt;h2&gt;why?&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="https://www.valheimgame.com/"&gt;Valheim&lt;/a&gt; is a fantastic game that currently
eats up most of my gaming time. The game so far offers no backup possibility,
but it has been reported that through a bug lots of people have lost their
world and their character. Taking a look at the directory with the valheim
files, there are already .old files for both world and character, which in many
cases is enough to restore. But there might be the case where one wants to
restore an older snapshot of his/her progress through valheim.&lt;/p&gt;
&lt;p&gt;This tool implements a watcher, that runs in the backgound, becomes active
every 5 minutes, then watches the valheim world and character files and creates
a backup right after the game itself has written the files (which also happens
periodically).&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="usage"&gt;
&lt;h2&gt;Usage&lt;/h2&gt;
&lt;p&gt;Open &lt;a class="reference external" href="https://github.com/svenXY/valheim-utils/"&gt;svenXY/valheim_utils&lt;/a&gt; for details&lt;/p&gt;
&lt;p&gt;Either build and use the docker container (see below) or do the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;git clone https://github.com/svenXY/valheim-utils
cd valheim-utils

# optional: create and/r activate a virtual environment
pip install requirements.txt

python valheim_backup --help

python valheim_backup \
    --source $HOME/.config/unity3d/IronGate/Valheim
    --destination $HOME//valheim_backup \
    --verbose

# do not close the terminal
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You are done. Now start Valheim and enjoy playing.&lt;/p&gt;
&lt;p&gt;&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;ctrl-c&lt;/span&gt; stops&lt;/tt&gt; the backup utility at any time.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="docker-container"&gt;
&lt;h2&gt;Docker container&lt;/h2&gt;
&lt;p&gt;This utility uses &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Inotify"&gt;inotify&lt;/a&gt; which is
not available for Windows and macOS, but at least on macOS, where docker
desktop runs docker through a transparent linux VM, inotify can be used.&lt;/p&gt;
&lt;p&gt;I've tested and it runs, but with no valheim installation available on my
macOS, I was not able to end-to-end test if it really works.  Maybe someone can
give me some clarification.&lt;/p&gt;
&lt;p&gt;Depending on how docker runs on Windows, it might also work on Windows. Again -
comments if this is actually possible are greatly appreciated.&lt;/p&gt;
&lt;p&gt;Important is to first pass the real (docker-external) source and destination to
the docker container as volumes, then set the docker-internal paths as source
and destination parameters as shown in the example below.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;docker run run -it --rm \
    -v $(pwd)/testdir:/usr/src/app/valheim \
    -v $(pwd)/backup:/backup \
    --name valheim_bck valheim_backup:latest \
    --source /usr/src/app/valheim \
    --destination /backup \
    --verbose
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="restore"&gt;
&lt;h2&gt;Restore&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;warning: always make a copy of your valheim directory before trying this!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The backups contain either the world or the character files. To restore
whichever you need, just extract them from the tgz file of your choice and copy
them into the worlds or characters directory.&lt;/p&gt;
&lt;p&gt;Again, for safety precautions, create a backup of the files there before overwriting
them!&lt;/p&gt;
&lt;p&gt;You do this at your own risk!&lt;/p&gt;
&lt;/div&gt;
</content><category term="gaming"></category><category term="valheim"></category><category term="backup"></category><category term="tool"></category><category term="python"></category></entry><entry><title>use autojump effectively with tmux</title><link href="https://www.hergenhahn-web.de/tmux-autojump.html" rel="alternate"></link><published>2020-12-09T08:48:43+01:00</published><updated>2020-12-09T08:48:43+01:00</updated><author><name>Sven Hergenhahn</name></author><id>tag:www.hergenhahn-web.de,2020-12-09:/tmux-autojump.html</id><summary type="html">&lt;p class="first last"&gt;a small function combines autojump with tmux to jump into a directory in a new tmux window&lt;/p&gt;
</summary><content type="html">&lt;p&gt;&lt;a class="reference external" href="https://github.com/wting/autojump"&gt;Autojump&lt;/a&gt; is a nice little tool that learns from your cd history and then allows you to directly jump
to a directory with just a few - even fuzzy - characters of the path by just issuing something along the lines of&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# destination path is abc/def/ghi&lt;/span&gt;

j&lt;span class="w"&gt; &lt;/span&gt;ab/hi
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The tj command (read tmux-jump) is a very small helper function that makes use of autojump, but instead of directly cd'ing, it opens a new tmux window and there
jumps to the selected directory. It also sets a proper name for the tmux window.&lt;/p&gt;
&lt;div class="section" id="the-code"&gt;
&lt;h2&gt;The Code&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;tj&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;autojump&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;basename&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$DIR&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;tmux&lt;span class="w"&gt; &lt;/span&gt;new-window&lt;span class="w"&gt; &lt;/span&gt;-c&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$DIR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$NAME&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="how-to-use-it"&gt;
&lt;h2&gt;How to use it&lt;/h2&gt;
&lt;p&gt;Put the code into a file, e.g. tmux-jump.zsh and source it. If you like it, add the command to source it to one of your shell initialization scripts.&lt;/p&gt;
&lt;p&gt;Then instead of j, run tj. If no path is found within the autojump database, nothing will happen. Otherwise, a new tmux window with a shell will be
opened in the found directory.&lt;/p&gt;
&lt;/div&gt;
</content><category term="howto"></category><category term="tmux"></category><category term="autojump"></category></entry><entry><title>two fzf-helpers for kubernetes</title><link href="https://www.hergenhahn-web.de/fzf_k8s.html" rel="alternate"></link><published>2020-11-10T00:00:00+01:00</published><updated>2020-11-10T00:00:00+01:00</updated><author><name>Sven Hergenhahn</name></author><id>tag:www.hergenhahn-web.de,2020-11-10:/fzf_k8s.html</id><summary type="html">&lt;p class="first last"&gt;... with a nice function for zsh&lt;/p&gt;
</summary><content type="html">&lt;div class="section" id="what-it-is"&gt;
&lt;h2&gt;What it is&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="https://github.com/junegunn/fzf/"&gt;FZF&lt;/a&gt; to create zsh functions to interactively select kubernetes pods for further usage.&lt;/p&gt;
&lt;p&gt;FZF is a nice tool for all kinds of fuzzy finding on your computer. It really shines when combined with other tools to make them interactive.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="what-it-does-for-you"&gt;
&lt;h2&gt;What it does for you&lt;/h2&gt;
&lt;p&gt;The two functions we create here can do the following for us:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;show all pods of a kubernetes cluster (optionally only those of a namespace)&lt;/li&gt;
&lt;li&gt;optinally takes an fzf query string to prepopulate fzf&lt;/li&gt;
&lt;li&gt;allow for fuzzy-finding the one we want with fzf interactively&lt;/li&gt;
&lt;li&gt;select one and then either start a bash shell in the container or show the logs for the container&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="the-code"&gt;
&lt;h2&gt;The Code&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;klogs&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;#--argument-names pod_name namespace&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;OPTIND&lt;span class="w"&gt; &lt;/span&gt;flag
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;getopts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;p:n:&amp;#39;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;flag&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;do&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$flag&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;p&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;pod_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$OPTARG&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;n&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$OPTARG&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;done&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;shift&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;OPTIND&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;remaining_args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-z&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$namespace&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;namespace_pod&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;kubectl&lt;span class="w"&gt; &lt;/span&gt;get&lt;span class="w"&gt; &lt;/span&gt;pods&lt;span class="w"&gt; &lt;/span&gt;-A&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;fzf&lt;span class="w"&gt; &lt;/span&gt;--header-lines&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-q&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$pod_name&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;awk&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;{print $1&amp;quot; &amp;quot;$2}&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;namespace_pod&lt;/span&gt;&lt;span class="p"&gt;%% *&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;pod&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;namespace_pod&lt;/span&gt;&lt;span class="p"&gt;##* &lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;pod&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;kubectl&lt;span class="w"&gt; &lt;/span&gt;get&lt;span class="w"&gt; &lt;/span&gt;pods&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$namespace&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;fzf&lt;span class="w"&gt; &lt;/span&gt;--header-lines&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-q&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$pod_name&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;awk&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;{print $1}&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-z&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$pod&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;Retrieving&lt;span class="w"&gt; &lt;/span&gt;logs&lt;span class="w"&gt; &lt;/span&gt;from&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$pod&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;kubectl&lt;span class="w"&gt; &lt;/span&gt;logs&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$namespace&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$remaining_args&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$pod&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;kbash&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;#--argument-names pod_name namespace&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;getopts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;:p:n:&amp;#39;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;arg&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;do&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;p&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;pod_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$OPTARG&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;n&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$OPTARG&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;done&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;shift&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="nv"&gt;$OPTIND&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;remaining_args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-z&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$namespace&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;namespace_pod&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;kubectl&lt;span class="w"&gt; &lt;/span&gt;get&lt;span class="w"&gt; &lt;/span&gt;pods&lt;span class="w"&gt; &lt;/span&gt;-A&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;fzf&lt;span class="w"&gt; &lt;/span&gt;--header-lines&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-q&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$pod_name&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;awk&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;{print $1&amp;quot; &amp;quot;$2}&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;namespace_pod&lt;/span&gt;&lt;span class="p"&gt;%% *&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;pod&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;namespace_pod&lt;/span&gt;&lt;span class="p"&gt;##* &lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;pod&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;kubectl&lt;span class="w"&gt; &lt;/span&gt;get&lt;span class="w"&gt; &lt;/span&gt;pods&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$namespace&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;fzf&lt;span class="w"&gt; &lt;/span&gt;--header-lines&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-q&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$pod_name&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;awk&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;{print $1}&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-z&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$pod&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;Executing&lt;span class="w"&gt; &lt;/span&gt;bash&lt;span class="w"&gt; &lt;/span&gt;on&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$pod&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;kubectl&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exec&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$namespace&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-it&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$pod&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--&lt;span class="w"&gt; &lt;/span&gt;bash
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="how-to-use-it"&gt;
&lt;h2&gt;How to use it&lt;/h2&gt;
&lt;p&gt;Put the code into a file, e.g. fzf_k8s.zsh and source it. If you like it, add the command to source it to one of your shell initialization scripts.&lt;/p&gt;
&lt;p&gt;Then run&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;kbash&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&amp;lt;namespace&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;-p&lt;span class="w"&gt; &lt;/span&gt;&amp;lt;pod&lt;span class="w"&gt; &lt;/span&gt;querystring&amp;gt;&lt;span class="o"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# or&lt;/span&gt;

klogs&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&amp;lt;namespace&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;-p&lt;span class="w"&gt; &lt;/span&gt;&amp;lt;pod&lt;span class="w"&gt; &lt;/span&gt;querystring&amp;gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;--&lt;span class="w"&gt; &lt;/span&gt;&amp;lt;other&lt;span class="w"&gt; &lt;/span&gt;kubectl&lt;span class="w"&gt; &lt;/span&gt;logs&lt;span class="w"&gt; &lt;/span&gt;options&amp;gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;to find the to find the pod you wish to interact with, type some more search
characters - it can be a fuzzy-find - and/or use the arrow keys to select a
pod.&lt;/p&gt;
&lt;p&gt;Then press &amp;lt;Enter&amp;gt; either start a bash shell or show the logs. Use &amp;lt;ESC&amp;gt; to exit without
doing anything.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;/div&gt;
</content><category term="howto"></category><category term="fzf"></category><category term="kubernetes"></category><category term="zsh"></category></entry><entry><title>bwtarif - eine Mogelpackung</title><link href="https://www.hergenhahn-web.de/bwtarif_mogelpackung.html" rel="alternate"></link><published>2020-11-09T10:07:00+01:00</published><updated>2020-11-09T10:07:00+01:00</updated><author><name>Sven Hergenhahn</name></author><id>tag:www.hergenhahn-web.de,2020-11-09:/bwtarif_mogelpackung.html</id><summary type="html">&lt;p class="first last"&gt;Wie mein Pendlerticket mal eben 33% teurer wurde&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Ich bin Inhaber eines Abo Plus VRN/KVV Tickets der Deutschen Bahn (DB), um
zwischen Heidelberg und Karlsruhe pendeln zu können.&lt;/p&gt;
&lt;p&gt;Dafür bezahle ich momentan monatlich 135€ (VRN Rhein-Neckar-Ticket + KVV mit 50%
Rabatt).&lt;/p&gt;
&lt;p&gt;Heute habe ich von der DB einen Brief erhalten, in dem mir angekündigt wird,
dass ich in Zukunft entweder den vollen KVV Preis bezahlen muss oder das tolle
neue bwABO beziehen könne, mit dem es billiger werden würde.&lt;/p&gt;
&lt;p&gt;Dem ist leider nicht so:&lt;/p&gt;
&lt;p&gt;Für beide Abos zusammen (RNV + KVV) ohne die 50% Rabatt komme ich auf 178,80€.&lt;/p&gt;
&lt;p&gt;Der BW-Tarifrechner kommt für mich auf 178,20€.&lt;/p&gt;
&lt;p&gt;Die Ersparnis hier ist also nicht einmal 1 Euro, im Vergleich zum bisherigen
Tarif ist es eine Verteuerung um ca. 45€, das sind rund 33%.&lt;/p&gt;
&lt;p&gt;Dafür kann ich das Ticket in der Freizeit nicht mehr nutzen, weder nach
Mannheim, noch ins Neckartal, noch in die Pfalz, es ist nur noch in Heidelberg,
Karlsruhe und auf der Strecke dazwischen gültig. Wie man in Zeiten, in denen man
wegen des Klimas mehr Menschen auch am Wochenende vom Auto weglocken will,
gleichzeitig das Angebot verschlechtern kann, nur um eine angebliche
Vereinfachung zu erreichen ist mir nicht verständlich. Für mich ist es eine
Verschlechterung des Angebots bei gleichzeitiger Verteuerung um ein Drittel!&lt;/p&gt;
&lt;p&gt;Man fragt sich, wie es überhaupt zu der Entscheidung kam, das Kombi-Ticket abzuschaffen?&lt;/p&gt;
&lt;p&gt;Wie viele andere Pendler gibt es auch für mich nicht erst seit Corona die
Möglichkeit des Homeoffice. Ich pendle in der Regel dreimal wöchentlich, komme
also auf etwa 12 Fahrten im Monat. Ohne jegliches Abo oder Monatskarte müsste
ich mit etwa 20€ pro Pendeltag rechnen und käme auf 240€ - zwar 35% mehr, aber
ohne jegliche Verpflichtung.&lt;/p&gt;
&lt;p&gt;Seit Februar bin ich Corona-bedingt darüberhinaus komplett im HomeOffice,
brauche also gar kein teures Ticket. Bisher habe ich von einer Kündigung auch
deswegen abgesehen, weil ich mich damit auch ein wenig an den trotzdem
anfallenden Kosten des ÖPNV solidarisch beteiligen wollte. Mir ist das Klima
wichtig und ich versuche, meinen Beitrag zu leisten, aber hier fühlt es sich an,
als solle man dafür ausgerechnet im grün regierten Baden-Württemberg noch extra
abkassiert werden.&lt;/p&gt;
&lt;p&gt;Ich möchte jetzt hier nicht anfangen gegenzurechnen, was mich die Nutzung des
Autos (das ohnehin vorhanden ist) kosten würde, da hat keines der &amp;quot;Angebote&amp;quot;
eine Chance, aber was hier gemacht wird ist klimapolitisch und verkehrspolitisch
Unsinn und wird vermutlich Viele wie mich, denen es ähnlich geht dazu
veranlassen wieder häufiger, wenn nicht immer, mit dem Auto zu fahren und von
solchen tollen &amp;quot;Angeboten&amp;quot; lieber Abstand zu nehmen.&lt;/p&gt;
&lt;p&gt;Ich werde nun auf jeden Fall zunächst kündigen, da ich nicht damit rechne, vor
März oder April wieder nach Karlsruhe fahren zu müssen. Für die wenigen
Fahrten innerhalb von Heidleberg werde ich mir dann einfach eine Fahrkarte
besorgen.&lt;/p&gt;
&lt;p&gt;Das spart mir bis dahin ein paar Hundert Euro und verlieren tue ich nichts, da
es bei der Bahn ja auch nicht so etwas wie einen Treuerabatt gibt...&lt;/p&gt;
&lt;p&gt;Schade eigentlich&lt;/p&gt;
</content><category term="rant"></category><category term="bwtarif"></category><category term="öpnv"></category></entry><entry><title>gopass secret selection with fzf</title><link href="https://www.hergenhahn-web.de/fzf_gopass.html" rel="alternate"></link><published>2020-10-02T16:07:00+02:00</published><updated>2020-10-02T16:07:00+02:00</updated><author><name>Sven Hergenhahn</name></author><id>tag:www.hergenhahn-web.de,2020-10-02:/fzf_gopass.html</id><summary type="html">&lt;p class="first last"&gt;... with a nice function for zsh&lt;/p&gt;
</summary><content type="html">&lt;div class="section" id="what-it-is"&gt;
&lt;h2&gt;What it is&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="https://github.com/junegunn/fzf/"&gt;FZF&lt;/a&gt; to create a zsh functiona to interactively search for passwords or other information in the gopass databases&lt;/p&gt;
&lt;p&gt;FZF is a nice tool for all kinds of fuzzy finding on your computer. It really shines when combined with other tools to make them interactive.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="what-it-does-for-you"&gt;
&lt;h2&gt;What it does for you&lt;/h2&gt;
&lt;p&gt;The function we create here can do the following for us:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;show all secrets from all password stores that gopass knows of&lt;/li&gt;
&lt;li&gt;optinally takes an fzf query string to prepopulate fzf&lt;/li&gt;
&lt;li&gt;allow for fuzzy-finding the one we want with fzf interactively&lt;/li&gt;
&lt;li&gt;help with the selection by showing any additional info of a secret in fzf's preview&lt;/li&gt;
&lt;li&gt;select one and copy it to the clipboard&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="the-code"&gt;
&lt;h2&gt;The Code&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;p&lt;span class="o"&gt;(){&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nv"&gt;QUERY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-z&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$QUERY&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;QUERY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;#39;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;gopass&lt;span class="w"&gt; &lt;/span&gt;show&lt;span class="w"&gt; &lt;/span&gt;-C&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;gopass&lt;span class="w"&gt; &lt;/span&gt;ls&lt;span class="w"&gt; &lt;/span&gt;--flat&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;fzf&lt;span class="w"&gt; &lt;/span&gt;-q&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$QUERY&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--preview&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;gopass show {}&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="how-to-use-it"&gt;
&lt;h2&gt;How to use it&lt;/h2&gt;
&lt;p&gt;Put the code into a file, e.g. fzf_gopass.zsh and source it. If you like it, add the command to source it to one of your shell initialization scripts.&lt;/p&gt;
&lt;p&gt;Then type&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;p

&lt;span class="c1"&gt;# optionally followed by some (fuzzy) search text to start with&lt;/span&gt;

p&lt;span class="w"&gt; &lt;/span&gt;goo
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Type some more search characters - it can be a fuzzy-find - and/or use the
arrow keys to select a branch.&lt;/p&gt;
&lt;p&gt;Then press &amp;lt;Enter&amp;gt; to copy the password to the clipboard. Use &amp;lt;ESC&amp;gt; to exit without
copying anything.&lt;/p&gt;
&lt;p&gt;You can also use this command to quickly get any additional information stored
in your secrets database.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;/div&gt;
</content><category term="howto"></category><category term="gopass"></category><category term="fzf"></category><category term="zsh"></category></entry><entry><title>git branch checkout made easy with fzf</title><link href="https://www.hergenhahn-web.de/fzf_git.html" rel="alternate"></link><published>2020-10-01T16:07:00+02:00</published><updated>2020-10-01T16:07:00+02:00</updated><author><name>Sven Hergenhahn</name></author><id>tag:www.hergenhahn-web.de,2020-10-01:/fzf_git.html</id><summary type="html">&lt;p class="first last"&gt;... with a nice function for zsh&lt;/p&gt;
</summary><content type="html">&lt;div class="section" id="what-it-is"&gt;
&lt;h2&gt;What it is&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="https://github.com/junegunn/fzf/"&gt;FZF&lt;/a&gt; to create a zsh functiona to interactively select a git branch to check out.&lt;/p&gt;
&lt;p&gt;FZF is a nice tool for all kinds of fuzzy finding on your computer. It really shines when combined with other tools to make them interactive.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="what-it-does-for-you"&gt;
&lt;h2&gt;What it does for you&lt;/h2&gt;
&lt;p&gt;The function we create here can do the following for us:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;show all branches of the current repository as a list&lt;/li&gt;
&lt;li&gt;optinally takes an fzf query string to prepopulate fzf&lt;/li&gt;
&lt;li&gt;allow for fuzzy-finding the one we want with fzf interactively&lt;/li&gt;
&lt;li&gt;help with the selection by showing the commit history of that branch in fzf's preview&lt;/li&gt;
&lt;li&gt;select one and automatically check it out&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="the-code"&gt;
&lt;h2&gt;The Code&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;gcx&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nv"&gt;my_branch&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;git&lt;span class="w"&gt; &lt;/span&gt;branch&lt;span class="w"&gt; &lt;/span&gt;-a&lt;span class="w"&gt; &lt;/span&gt;--no-color&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;sort&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;uniq&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;tr&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot; &amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;fzf&lt;span class="w"&gt; &lt;/span&gt;--select-1&lt;span class="w"&gt; &lt;/span&gt;--ansi&lt;span class="w"&gt; &lt;/span&gt;--preview&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;git log --graph --color=always --format=&amp;quot;%C(auto)%h%d %s %C(black)%C(bold)%cr&amp;quot; {} 2&amp;gt;/dev/null&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$my_branch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;grep&lt;span class="w"&gt; &lt;/span&gt;-q&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;remotes/origin&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;my_branch&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;my_branch&lt;/span&gt;&lt;span class="p"&gt;##remotes/origin/&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$my_branch&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;grep&lt;span class="w"&gt; &lt;/span&gt;-q&lt;span class="w"&gt; &lt;/span&gt;-P&lt;span class="w"&gt; &lt;/span&gt;--regexp&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;\*&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;my_branch&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;my_branch&lt;/span&gt;&lt;span class="p"&gt;##&lt;/span&gt;&lt;span class="se"&gt;\*&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;git&lt;span class="w"&gt; &lt;/span&gt;checkout&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$my_branch&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="how-to-use-it"&gt;
&lt;h2&gt;How to use it&lt;/h2&gt;
&lt;p&gt;Put the code into a file, e.g. fzf_git.zsh and source it. If you like it, add the command to source it to one of your shell initialization scripts.&lt;/p&gt;
&lt;p&gt;Then run&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;gcx

&lt;span class="c1"&gt;# or provide some (fuzzy) search text to start with&lt;/span&gt;

gcx&lt;span class="w"&gt; &lt;/span&gt;feat
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and it will look similarly to this:&lt;/p&gt;
&lt;img alt="git checkout with fzf" src="https://www.hergenhahn-web.de/images/fzf_git.png" /&gt;
&lt;p&gt;to find the branch you want to checkout, type some more search characters - it
can be a fuzzy-find - and/or use the arrow keys to select a branch.&lt;/p&gt;
&lt;p&gt;Then press &amp;lt;Enter&amp;gt; to check the selected branch out. Use &amp;lt;ESC&amp;gt; to exit without
checking out.&lt;/p&gt;
&lt;p&gt;You can also use this command to quickly get some overview about the commit
history in different branches.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;/div&gt;
</content><category term="howto"></category><category term="git"></category><category term="fzf"></category><category term="zsh"></category></entry></feed>