Skip to content

Instantly share code, notes, and snippets.

View vhbui02's full-sized avatar

VH vhbui02

View GitHub Profile
@vhbui02
vhbui02 / fish-event-handlers.md
Created April 29, 2023 02:24
[Event Handlers in Fish] linked functions with event #fish

When defining a new function in fish, it's possible to make it into an event handler - a function that is automatically run when a specific event takes place.

*Note: event handler is a function, but a function isn't an event handler.

Events that can trigger a handler currently are:

  • A signal is delivered
  • A job exits
  • The value of a variable is updated

Some noted event handlers

@vhbui02
vhbui02 / fish-conf-file.md
Last active April 29, 2023 03:06
[Configuration File in Fish] some file/directory that funcs are loaded when startup #fish

Here are some files/directories are run in the following order, that worth to note:

Configuration snippets (named *.fish)

  • ~/.config/fish/conf.d/: fish local config dir
  • /etc/fish/conf.d/: fish system config dir

If some softwares need specific configuration snippets, they can be put inside:

  • $XDG_DATA_HOME/fish controlled by $XDG_DATA_HOME (default value is $HOME/.local/share)
@vhbui02
vhbui02 / fish-autoloading-function.md
Created April 29, 2023 03:23
[Autoloading Functions in Fish] a.k.a lazy loading function #fish

Autoloading = Lazy loading

When fish needs to load a function

It searches through any dirs in the list variable $fish_function_path, for a file with name that consists the func name + suffix .fish and loads the 1st file it finds (remember, 1st)

If you put multiple funcs in 1 file .fish

The file (whole file, not just 1 func) will ONLY be loaded when you execute a function with the same name as that file.

@vhbui02
vhbui02 / 4-func-command.md
Last active April 29, 2023 03:53
[Quick reminder about function, functions, funced and funcsave] 4 built-in command in Fish that fvck the brain of devs #fish

Remember

  • function: Create
  • functions: Read and Delete
  • funced: Update
  • funcsave: Update (support), Delete (support)
@vhbui02
vhbui02 / fish-status.md
Created April 29, 2023 05:04
[status command] query fish runtime information #fish

Some option that needs to be remembered

status: no arguments, simply display the current login and job control status of the Fish shell.

status is-login / --is-login / -l: return 0 if current Fish shell is a login shell

status is-interactive / --is-interactive / -i: return 0 if current Fish shell is interactive (connected to a keyboard)

status is-block / --is-block / -b: return 0 if fish is currently executing a block of code.

@vhbui02
vhbui02 / dir-handler.md
Last active April 30, 2023 14:07
[Directory handlers command] basename, dirname, realpath #linux

Dirname

dirname [OPTION] NAME

Extract the path to get to the file called NAME (excluding the NAME itself).

Absolute path:

dirname /foo/bar/baz => /foo/bar (notice the / before foo is existed)

@vhbui02
vhbui02 / type.md
Last active May 3, 2023 07:38
[type command] locate a command and describe its type #fish

type [OPTIONS] NAME

Option

-a or --all: prints exe, function (with definition expansion), and built-in.

-s or --short: suppresses function definition expansion.

-f or --no-function: suppresses function and built-in lookup.

-t or --type: prints the type currently working of command:

@vhbui02
vhbui02 / redirect.md
Created May 1, 2023 02:03
[redirect] Manipulate stream #linux

Ampersand

2>1: redirect stderr to a file called 1 2>&1: redirect stderr to stdout

Note: 1 and 2 are called file descriptor.

Note 2: > and 1> are the same.

Redirect stdout and stderr to different locations

@vhbui02
vhbui02 / changes-might-be-override-by-update.md
Created May 1, 2023 03:07
[Some files I've changed but might be override to default by update in the future] #fish #linux

List of files i've changed

D:\Development_Tools\Visual Paradigm CE 17.0\bin: Visual Paradigm.exe to vp.exe

/usr/share/fish/functions/__fish_anypython.fish: I've changed:

for py in python3 python3.{9,8,7,6,5,4,3} python2 python2.7 python

to

@vhbui02
vhbui02 / for.md
Last active May 2, 2023 03:41
[for command] perform a set of commands multiple times #fish #linux

local variable inside for body isn't exported to outside, remember to use set -x option.

Syntax

for <var-name> in $list_variable
	echo $<var-name>
end