config.phundrak.com/.config/fish
2019-12-28 22:20:18 +01:00
..
functions Forgot to remove these files 2019-11-06 17:00:30 +01:00
config.fish Updated PATH variable 2019-12-28 22:20:18 +01:00
README.org Updated PATH variable 2019-12-28 22:20:18 +01:00

Phundraks fish config

Presentation

The file present in ~/.config/fish/config.fish is the configuration file for the fish shell. It contains custom functions, environment variables and abbreviations.

Just in case, we might need sometimes to declare the fish function fish_title as true, so lets do so.

  function fish_title
      true
  end

Fish from within Emacs

I sometimes call fish from within emacs, with M-x ansi-term. In this case, the variable TERM needs to have the value eterm-color.

  if test -n "$EMACS"
      set -x TERM eterm-color
  end

Tramp remote access

When accessing from a remote machine our computer from Emacs, tramp needs a precise shell appearance: a simple $ followed by a space after which to put the commands it needs to execute, and nothing else. Due to this, lets deactivate and redefine some of the functions defining the appearance of fish.

  if test "$TERM" = "dumb"
      function fish_prompt
          echo "\$ "
      end
      function fish_right_prompt; end
      function fish_greeting; end
      function fish_title; end
  end

Regular fish shell appearance

Now, there is only one function I modify when it comes to the appearance of fish when Im the one using it: I simply “delete” the fish_greeting function.

  function fish_greeting; end

Global variables

Some global variables might sometimes be needed and need to be modified. This is for example the case with my PATH variable in which I add Rusts Cargos binaries, Gos binaries and my own executables. And of course, dont forget to add the already existing PATH.

  set -gx PATH \
  $HOME/.pub-cache/bin $HOME/.local/bin $HOME/go/bin $HOME/.cargo/bin \
  $HOME/.gem/ruby/2.6.0/bin $PATH

Sometimes, software will rely on SUDO_ASKPASS to get a GUI from which it can get the sudo password. So, lets declare it.

  set -gx SUDO_ASKPASS ~/.local/bin/askpass

Now, lets declare our editor of choice, EmacsClient; not Emacs itself since it will most often be just quick edits, nothing too heavy, if it is called from the EDITOR variable (from Git, for example).

  set -gx EDITOR emacsclient -c

We also need to set the path to the Dart SDK.

set -gx DART_SDK /opt/dart-sdk/bin

And we also need to specify where the Android SDK it located.

set -gx ANDROID_HOME $HOME/Android/Sdk

Finally, some development packages require the PKG_CONFIG_PATH to be set, so lets do so.

  set -gx PKG_CONFIG_PATH /usr/local/lib/pkgconfig/ $PKG_CONFIG_PATH

Theme customization

The theme I use is bobthefish. Although its default configuration is quite alright, it allows some customization. The first thing I want to enable is the support for nerd-fonts:

  set -g theme_nerd_fonts_support yes

Next, I want the name of the current process to be shown in the terminal title.

  set -g theme_title_display_process yes

I also wish to display the current host in the prompt, but only when I am connected through an SSH session.

  set -g theme_display_hostname ssh

I also want the sudo username to be displayed, as a warning that I am indeed running a session as root.

  set -g theme_display_sudo_user yes

The exit status can be sometimes really useful, hence why I want it activated.

  set -g theme_show_exit_status yes

I also want to have proper git worktree support.

  set -g theme_git_worktree_support yes

Abbreviations

System monitoring

Here I have some abbreviations which are quite useful when performing some system monitoring. With df, we can get an overview of our filesystem usage, while with diskspace we get some more precise information.

  abbr df 'df -H'
  abbr diskspace 'sudo df -h | grep -E "sd|lv|Size"'

meminfo is a call to free with sane defaults.

  abbr meminfo 'free -m -l -t'

Similar to meminfo, we also have gpumeminfo so we can get a quick look at the memory-related logs of our X session.

  abbr gpumeminfo 'grep -i --color memory /var/log/Xorg.0.log'

I also declared cpuinfo an alias of lscpu in order to keep consistent with meminfo.

  abbr cpuinfo lscpu

pscpu gives us information on what the CPU is running right now, and pscpu10 limits that to the top 10 threads.

  abbr pscpu 'ps auxf | sort -nr -k 3'
  abbr pscpu10 'ps auxf | sort -nr -k 3 | head -10'

Similarly, psmem gives us information on the memory usage of the current threads, and psmem10 only the ten most important threads in terms of memory usage.

  abbr psmem 'ps auxf | sort -nr -k 4'
  abbr psmem10 'ps auxf | sort -nr -k 4 | head -10'

System management (packages and services)

I added some of these abbreviations due to how often I have to write the whole thing.

Package mangaement

The first command is remove which removes a package from my system, as well as its dependencies no longer needed.

  abbr remove 'sudo pacman -Rscnd'

But if I just want to run pacman as sudo, then I could always just type p.

  abbr p 'sudo -A pacman'

Sometimes, I just want to purge my package managers cache, be it pacman's or yay's. This is why I simply type purge.

  abbr purge 'yay -Sc'

And if I want to simply seach among the pacman repos, I can type search. Otherwise, if I want to include AUR results, Ill use yay.

  abbr search 'pacman -Ss'

To update everything from the official repos, Ill sometimes type update instead of the full command.

  abbr update 'sudo pacman -Syu'

Service management

I dont have the muscle memory of systemctl. So instead, I simply type c when I want to do something user service related.

  abbr s 'systemctl --user'

And if I want to manipulate system services, I can instead type a simple capital S.

  abbr S 'sudo systemctl'

Development

A good amount of these commands are development related, especially when it comes to compilation or Docker.

CMake

I have the following abbreviations so I can quickly run CMake and create a configuration for debug or release profiles.

  abbr cdebug 'cmake -DCMAKE_BUILD_TYPE=Debug'
  abbr crelease 'cmake -DCMAKE_BUILD_TYPE=Release'

Compilation

By default, I set clang, clang++, gcc and g++ to the latest standard and with the -Wall flag activated.

  abbr clang 'clang -Wall'
  abbr clang++ 'clang++ -Wall'
  abbr g++ 'g++ -Wall -std=c++17'
  abbr gcc 'gcc -Wall -std=c18'

Docker

And of course, when it comes to Docker Compose, I dont have time to write the full command, so I use these instead.

  abbr dc docker-compose
  abbr dcd 'docker-compose down'
  abbr dcr 'docker-compose run --rm'
  abbr dcu 'docker-compose up'
  abbr dcub 'docker-compose up --build'

Git

And lets face it: we all at one point just wanted to commit our code without thinking about the message, to just get over with it. Dont worry, I got you covered.

  abbr randcommit 'git commit -m (curl -s whatthecommit.com/index.txt)'

Prolog

When I launch swipl, I prefer to have my terminal cleaned before and after it runs, I find it more clean.

  abbr swipl 'clear && swipl -q && clear'

Text editors

I greatly prefer to use Emacsclient as my main text editor; Emacs has basically all I need. So, its only normal I have an abbreviation to launch a new instance of it.

  abbr e 'emacsclient -c'

However, in a graphical environment, this will launch a new graphical window of Emacs. To launch a terminal instance, Ill use enw (nw stands for the option “nowindow” -nw of Emacs).

  abbr enw 'emacsclient -c -nw'

I also have the abbreviation vi which refers to vim. I really should learn vi, but I also really dont feel like it.

  abbr vi vim

LaTeX

Yes, although I use org-mode, I still have some use for LaTeX, especially when it comes to PDF exports of my org files. Hence why I use the LaTeX package manager. It is recommended to use tllocalmgr instead of tlmgr, but I can never remember the command, and the latter is faster to type, so time for an abbreviation.

abbr tlmgr tllocalmgr
abbr texhash 'sudo texhash'

Some security measures

Some commands can be quite dangerous when not used properly, which is why I added default flags and options so I can get warnings before things get ugly.

  abbr cp 'cp -i'
  abbr ln 'ln -i'
  abbr lns 'ln -si'
  abbr mv 'mv -i'
  abbr rm 'rm -I'
  abbr rmd 'rm --preserve-root -Ir'
  abbr rmdf 'rm --preserve-root -Irf'
  abbr rmf 'rm --preserve-root -If'

The -i and -I add prompts in case we might not want to do what we asked the shell to do. Notice lns which creates symlinks, rmd which removes directories, rmf which forces deletion, and rmdf which forces the delition of a directory. Notice also the --preserve-root which will prevent me from accidentally removing the root folder. I added the same option to chgrp, chmod, and chown.

  abbr chgrp 'chgrp --preserve-root'
  abbr chmod 'chmod --preserve-root'
  abbr chown 'chown --preserve-root'

Typos

Lets admit it, we all make typos from time to time in the shell, and some are recurrent enough we make abbreviations or aliases of the correct command. Well, I have some of my abbreviations which were make exactly because of this.

Sometimes for some reasons, my brain makes me write clean instead of clear. So, lets just replace the former by the latter.

abbr clean clear

Im also very bad at typing exit.

  abbr exi exit
  abbr exti exit

And sometimes I suck at typing htop.

  abbr hotp htop

Misc

Finally, some miscellaneous abbreviations that dont really fit into any of the above categories.

Sudo

First, I make it so that sudo comes with the -A switch in order to call my custom graphical script for getting my password (see .local/bin/askpass). I also made it so please is an equivalent to sudo -A as a joke.

  abbr sudo 'sudo -A'
  abbr please 'sudo -A'

Exit

Sometimes I find it easier to just type q instead of exit.

  abbr q exit

History

I also find it more intuitive and faster to just write hist instead of history, so lets declare that.

  abbr hist history

Song download from YouTube

When I want to download a song from YouTube, Ill just use the command flac videoIdentifier to get it through youtube-dl.

  abbr flac 'youtube-dl -x --audio-format flac --audio-quality 0'

MPV

When it comes to mpv, I do not want to force it to open a graphical window if for example I want to listen to an audio file. I also do not want any border on that window. So, I declared this abbreviation.

  abbr mpv 'mpv --no-border --force-window=no'

Compression

It seems its just like many other people, but I cannot for the life of me remember the syntax of tar. So, I made the following abbreviations, and one day hopefully, after seeing the abbreviations expansion over and over Ill remember the command like I did for the abbreviation of remove (see Package management).

  abbr compress 'tar -czf'
  abbr untar 'tar -xvzf'

Feh

Some sane default options for feh, including auto-zoom to fit the picture to the window, a borderless window, and again scale the image to fit the window geometry.

  abbr feh 'feh -Zx.'

ls

Yep, an abbreviation of ls called lsl. It allows me to view all the files in a directory as a list with detailed, human-readable information.

  abbr lsl 'ls -ahl'

Network Management

First, we have just nmcli with sane default options, that is a pretty output with colors.

  abbr nmcli 'nmcli -p -c auto'

Next, we have some NordVPN-related shortcuts. The first one is a simple abbreviation to nordvpn. The second one is a shortcut to connect to a server, and to disconnect from the current server.

  abbr n 'nordvpn'
  abbr nc 'nordvpn c'
  abbr nd 'nordvpn d'

I also have a couple of shortcuts to quickly connect to some preselected countries, mainly France, Germany, Japan and the US.

  abbr ncf 'nordvpn c France'
  abbr ncg 'nordvpn c Germany'
  abbr ncj 'nordvpn c Japan'
  abbr ncu 'nordvpn c United_States'

Wget

By default, continue a download that was interupted.

  abbr wget 'wget -c'