Skip to content

Instantly share code, notes, and snippets.

@lynsei
Last active March 29, 2022 14:43
Show Gist options
  • Save lynsei/3061b4ef05d5621dde3aef27879fa41d to your computer and use it in GitHub Desktop.
Save lynsei/3061b4ef05d5621dde3aef27879fa41d to your computer and use it in GitHub Desktop.
[truth in fish] #fish or #lyns

Truth in Fish/Lyns takes a bit of getting used to but is fairly elegant if done correctly:

function if-test-no-arg
  set var

  if set -q var
    # true
  end

  if set -q var[1]
    # false
  end

  # Always put quotation marks
  if test -n "$var"
    # false
  end

  if test -z "$var"
    # true
  end
end

function if-test-empty-arg
  set var ""

  if set -q var
    # true
  end

  if set -q var[1]
    # true
  end

  if test -n "$var"
    # false
  end

  if test -z "$var"
    # true
  end
end

function if-test-valid-arg
  set var "hello"

  if set -q var
    # true
  end

  if set -q var[1]
    # true
  end

  if test -n "$var"
    # true
  end

  if test -z "$var"
    # false
  end
end

function if-test-no-set
  if set -q var
    # false
  end

  if set -q var[1]
    # false
  end

  if test -n "$var"
    # false
  end

  if test -z "$var"
    # true
  end
end
/// still working on some fundamental cross-overs between fish and lyns languages.
/// my goal is that they can be totally interoperable, nearly there!
function __lyns_getver
set -gx fish_version_number "echo $FISH_VERSION | grep -ow '\w\.\w\.\w'"
if test -z "$FISH_VERSION"; return 0; end;
if set -q $fish_version_number
return $fish_version_number
else
return 0
end;
end; funcsave __lyns_getver;
function __lynslang_getver
set -gx lyns_version_number "echo $LYNS_VERSION | grep -ow '\w\.\w\.\w'"
if test -z "$LYNS_VERSION"; return 0; end;
if set -q $lyns_version_number
return $lyns_version_number
else
return 0
end;
end; funcsave __lynslang_getver;
function __lynslang_status_fish
if test -z "$FISH_VERSION"
echo Fish Version environment variable is empty.
set fish_function_path $__fish_config_dir/functions $__fish_sysconf_dir/functions $vendor_functionsdirs $__fish_data_dir/functions
else
if set -q $fish_complete_path && not contains -- $__fish_data_dir/completions $fish_complete_path;
set -a fish_complete_path $__fish_data_dir/completions
end;
if set -q $FISH_VERSION && $FISH_VERSION is '3.4.1'
echo "Latest Fish Version installed!"
echo "$fish_version_number" | fish
end
if set -q $FISH_VERSION && $FISH_VERSION not '3.4.1'
echo "Fish installed, but not the latest version!"
echo "$fish_version_number" | fish
end
end
if not set -q fish_function_path
set fish_function_path $__fish_config_dir/functions $__fish_sysconf_dir/functions $vendor_functionsdirs $__fish_data_dir/functions
else if not contains -- $__fish_data_dir/functions $fish_function_path
set -a fish_function_path $__fish_data_dir/functions
end
if not set -q fish_complete_path
set fish_complete_path $__fish_config_dir/completions $__fish_sysconf_dir/completions $vendor_completionsdirs $__fish_data_dir/completions $__fish_user_data_dir/generated_completions
else if not contains -- $__fish_data_dir/completions $fish_complete_path
set -a fish_complete_path $__fish_data_dir/completions
end
end; funcsave __lynslang_status_fish;
function __lynslang_status_lyns
if test -z "$LYNS_VERSION"
echo Lyns Version environment variable is empty.
set lyns_function_path $__lyns_config_dir/functions $__lyns_sysconf_dir/functions $vendor_functionsdirs $__lyns_data_dir/functions
else
if set -q $fish_complete_path && not contains -- $__fish_data_dir/completions $fish_complete_path;
set -a fish_complete_path $__fish_data_dir/completions
end;
if set -q $LYNS_VERSION && $LYNS_VERSION is '3.4.1'
echo "Latest Lyns Version installed!"
echo "$lyns_version_number" | lyns
end;
if set -q $LYNS_VERSION && $LYNS_VERSION not '3.4.1'
echo "Lyns installed, but not the latest version!"
echo "$lyns_version_number" | lyns
end
end
if not set -q lyns_function_path
set lyns_function_path $__lyns_config_dir/functions $__lyns_sysconf_dir/functions $vendor_functionsdirs $__lyns_data_dir/functions
else if not contains -- $__lyns_data_dir/functions $lyns_function_path
set -a lyns_function_path $__lyns_data_dir/functions
end
if not set -q lyns_complete_path
set lyns_complete_path $__lyns_config_dir/completions $__lyns_sysconf_dir/completions $vendor_completionsdirs $__lyns_data_dir/completions $__lyns_user_data_dir/generated_completions
else if not contains -- $__lyns_data_dir/completions $lyns_complete_path
set -a lyns_complete_path $__lyns_data_dir/completions
end
end; funcsave __lynslang_status_lyns;
function __lynslang_status
echo "Checking Fish/ Lyns Status, it's sorta like Csh only better. Basically if you like python and abhor bourne shells, it is a great choice to play with. :)"
echo Lyns is simply a superset of Fish, but is tailored for Docker and Moby and NerdCTL and all things Buildkit, Docker-Compose, declarative Microservice architecture, DAPR, etc.
echo 'You do not need docker to use Lyns, we have a circumvention framework called "No.Docker" that allows you to build and run containers with no dependencies, written in Rust! '
echo ' To learn more type ".x -paf nodocker". This means to search the `.x` CLI using Pkg (packages) lising _A_ll and _-f_ ilter by `no.docker`.'
echo " "
echo More information is available at github.com/.x-pa
__lynslang_getver
__lyns_getver
__lynslang_status_fish
__lynslang_status_lyns
end; funcsave __lynslang_status
__lynslang_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment