Compare commits

...

10 Commits

12 changed files with 319 additions and 68 deletions

View File

@ -1,11 +1,11 @@
# Defines autocompletion for SDKMAN! # Defines autocompletion for SDKMAN!
# Copyright (c) 2018 Raphael Reitzig # Copyright (c) 2018-2023 Raphael Reitzig
# MIT License (MIT) # MIT License (MIT)
# https://github.com/reitzig/sdkman-for-fish # https://github.com/reitzig/sdkman-for-fish
# Guard: SDKMAN! needs to be installed # Guard: SDKMAN! needs to be installed
if not test -f "$HOME/.sdkman/bin/sdkman-init.sh" if not test -f "$SDKMAN_DIR/bin/sdkman-init.sh"
exit 0 exit 0
end end
@ -88,14 +88,14 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \
-d 'Install new version' -d 'Install new version'
complete -c sdk -f -n '__fish_sdkman_using_command i install' \ complete -c sdk -f -n '__fish_sdkman_using_command i install' \
-a "(__fish_sdkman_candidates)" -a "(__fish_sdkman_candidates)"
# TODO complete available versions --> issue #4
complete -c sdk -f -n '__fish_sdkman_specifying_candidate i install' \ complete -c sdk -f -n '__fish_sdkman_specifying_candidate i install' \
# TODO complete available versions --> #4
-a 'a.b.c' \ -a 'a.b.c' \
-d "version list unavailable" -d "version list unavailable"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate i install' \ complete -c sdk -f -n '__fish_sdkman_specifying_candidate i install' \
-a 'x.y.z' \ -a 'x.y.z' \
-d "Add your own; specify path!" -d "Specify path to install custom version."
# Implicit: complete files as fourth parameter # Implicit: complete files as fourth parameter
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 3 i install' complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 3 i install'
# block # block
@ -165,16 +165,9 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 v version' complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 v version'
# block # block
# broadcast
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'b broadcast' \
-d 'Display broadcast message'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 b broadcast'
# block
# help # help
complete -c sdk -f -n '__fish_sdkman_no_command' \ complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'h help' \ -a 'help' \
-d 'Display help message' -d 'Display help message'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 h help' complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 h help'
# block # block
@ -212,15 +205,39 @@ complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 update'
# flush # flush
complete -c sdk -f -n '__fish_sdkman_no_command' \ complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'flush' \ -a 'flush' \
-d 'Clear out caches' -d 'Clear out archives and temporary storage folders'
complete -c sdk -f -n '__fish_sdkman_using_command flush' \
-a 'broadcast' \
-d 'Re-download news'
complete -c sdk -f -n '__fish_sdkman_using_command flush' \
-a 'archives' \
-d 'Remove downloads'
complete -c sdk -f -n '__fish_sdkman_using_command flush' \ complete -c sdk -f -n '__fish_sdkman_using_command flush' \
-a 'temp' \ -a 'temp' \
-d 'Clear installation prep folder' -d 'Clear out staging work folder'
complete -c sdk -f -n '__fish_sdkman_using_command flush' \
-a 'version' \
-d 'Flush version file'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 flush' complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 flush'
# block # block
# env
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'e env' \
-d 'Load environment from .sdkmanrc file'
complete -c sdk -f -n '__fish_sdkman_using_command e env' \
-a 'init' \
-d 'Initialize .sdkmanrc file'
complete -c sdk -f -n '__fish_sdkman_using_command e env' \
-a 'install' \
-d 'Install all candidate versions listed in .sdkmanrc'
complete -c sdk -f -n '__fish_sdkman_using_command e env' \
-a 'clear' \
-d 'Unload currently loaded environment'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 e env'
# block
# home
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'h home' \
-d 'Show installation folder of given candidate'
complete -c sdk -f -n '__fish_sdkman_using_command h home' \
-a "(__fish_sdkman_candidates_with_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate h home' \
-a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 h home'
# block

View File

@ -14,8 +14,9 @@ function __fzf_files
2>/dev/null | 2>/dev/null |
fzf \ fzf \
--ansi \ --ansi \
--info=inline-right \
--preview='bat --style=numbers --color=always {}' \ --preview='bat --style=numbers --color=always {}' \
--preview-window='right,70%,wrap,hidden,<200(bottom,50%,hidden)' \ --preview-window='right,70%,wrap,hidden,<100(bottom,50%,hidden)' \
--bind='?:toggle-preview' \ --bind='?:toggle-preview' \
--expect='ctrl-e' \ --expect='ctrl-e' \
--header='ctrl-e to edit, ? to preview' --header='ctrl-e to edit, ? to preview'
@ -28,6 +29,7 @@ function __fzf_files
switch $key switch $key
case ctrl-e case ctrl-e
commandline -r "edit $file" commandline -r "edit $file"
commandline -f execute
case '*' case '*'
commandline -i $file commandline -i $file
end end
@ -42,9 +44,10 @@ function __fzf_git_log
git logsearch $argv | git logsearch $argv |
fzf \ fzf \
--ansi \ --ansi \
--info=inline-right \
--tiebreak=index \ --tiebreak=index \
--preview="git show {2} $argv | delta" \ --preview="git show {2} $argv | delta" \
--preview-window='right,70%,wrap,hidden,<200(bottom,50%,hidden)' \ --preview-window='right,70%,wrap,hidden,<100(bottom,50%,hidden)' \
--bind='?:toggle-preview' \ --bind='?:toggle-preview' \
--header='? to preview' --header='? to preview'
) )
@ -63,6 +66,7 @@ function __fzf_history
--show-time="%Y-%m-%d$separator" | --show-time="%Y-%m-%d$separator" |
fzf \ fzf \
--read0 \ --read0 \
--info=inline-right \
--tiebreak=index \ --tiebreak=index \
--query=(commandline) \ --query=(commandline) \
--preview='echo {3..}' \ --preview='echo {3..}' \

View File

@ -3,12 +3,23 @@
# Makes command and binaries from SDKMAN! available in fish. # Makes command and binaries from SDKMAN! available in fish.
# Delegates to bash for the `sdk` command. # Delegates to bash for the `sdk` command.
# Copyright (c) 2018 Raphael Reitzig # Copyright (c) 2018-2023 Raphael Reitzig
# MIT License (MIT) # MIT License (MIT)
# https://github.com/reitzig/sdkman-for-fish # https://github.com/reitzig/sdkman-for-fish
set __fish_sdkman_init "$HOME/.sdkman/bin/sdkman-init.sh" # Account for custom install locations
set __fish_sdkman_noexport_init "$HOME/.config/fisher/github.com/reitzig/sdkman-for-fish/sdkman-noexport-init.sh" if set -q __sdkman_custom_dir
set -gx SDKMAN_DIR "$__sdkman_custom_dir"
else
# This is the default location:
set -gx SDKMAN_DIR "$HOME/.sdkman"
end
set __fish_sdkman_init "$SDKMAN_DIR/bin/sdkman-init.sh"
# Copied from https://github.com/jorgebucaran/fisher/blob/main/functions/fisher.fish to be consistent:
set --query fisher_path || set --local fisher_path $__fish_config_dir
set __fish_sdkman_noexport_init "$fisher_path/functions/__sdkman-noexport-init.sh"
# Guard: SDKMAN! needs to be installed # Guard: SDKMAN! needs to be installed
if not test -f "$__fish_sdkman_init" if not test -f "$__fish_sdkman_init"
@ -42,7 +53,8 @@ function __fish_sdkman_run_in_bash
echo -e \"\$?\" > $pipe; echo -e \"\$?\" > $pipe;
env | grep -e '^SDKMAN_\|^PATH' >> $pipe; env | grep -e '^SDKMAN_\|^PATH' >> $pipe;
env | grep -i -E \"^(`echo \${SDKMAN_CANDIDATES_CSV} | sed 's/,/|/g'`)_HOME\" >> $pipe; env | grep -i -E \"^(`echo \${SDKMAN_CANDIDATES_CSV} | sed 's/,/|/g'`)_HOME\" >> $pipe;
echo \"SDKMAN_OFFLINE_MODE=\${SDKMAN_OFFLINE_MODE}\" >> $pipe" # it's not an environment variable! echo \"SDKMAN_OFFLINE_MODE=\${SDKMAN_OFFLINE_MODE}\" >> $pipe;
echo \"SDKMAN_ENV=\${SDKMAN_ENV}\" >> $pipe" # it's not an environment variable!
set bashDump (cat $pipe; rm $pipe) set bashDump (cat $pipe; rm $pipe)
set sdkStatus $bashDump[1] set sdkStatus $bashDump[1]
@ -65,7 +77,7 @@ function __fish_sdkman_run_in_bash
if test -n value if test -n value
set -gx $var $value set -gx $var $value
# Note: This makes SDKMAN_OFFLINE_MODE an environment variable. # Note: This makes SDKMAN_{OFFLINE_MODE,ENV} environment variables.
# That gives it the behaviour we _want_! # That gives it the behaviour we _want_!
end end
end end
@ -77,8 +89,16 @@ end
# If this is a subshell of a(n initialized) fish owned by the same user, # If this is a subshell of a(n initialized) fish owned by the same user,
# no initialization necessary. # no initialization necessary.
# Otherwise: # Otherwise:
if not set -q SDKMAN_DIR; or test (ls -ld "$SDKMAN_DIR" | awk '{print $3}') != (whoami) if not set -q SDKMAN_CANDIDATES_DIR; or test (ls -ld "$SDKMAN_CANDIDATES_DIR" | awk '{print $3}') != (whoami)
set -e SDKMAN_DIR
__fish_sdkman_run_in_bash "source $__fish_sdkman_init" __fish_sdkman_run_in_bash "source $__fish_sdkman_init"
end end
# Set up auto_env
if grep -q "^sdkman_auto_env=true" "$SDKMAN_DIR/etc/config"
function __fish_sdkman_autoenv --on-variable PWD
# Run the (modified) init script, which performs the checks and calls for us!
__fish_sdkman_run_in_bash "source \"$__fish_sdkman_noexport_init\""
set -x SDKMAN_OLD_PWD "$PWD" # needed by the Bash implementation
end
end

View File

@ -49,9 +49,6 @@ if status --is-interactive
# By default, Ctrl+L clears the screen # By default, Ctrl+L clears the screen
# Add binding Ctrl+Alt+L to clear screen AND scrollback buffer # Add binding Ctrl+Alt+L to clear screen AND scrollback buffer
bind \e\f 'clear; commandline -f repaint' bind \e\f 'clear; commandline -f repaint'
# Expand '...' to '../..'
bind . expand_dots
end end
if not set -q __universals_initialized if not set -q __universals_initialized

View File

@ -2,4 +2,4 @@ jorgebucaran/fisher
jorgebucaran/nvm.fish jorgebucaran/nvm.fish
jorgebucaran/replay.fish jorgebucaran/replay.fish
lilyball/nix-env.fish lilyball/nix-env.fish
reitzig/sdkman-for-fish@v1.4.0 reitzig/sdkman-for-fish@v2.0.0

View File

@ -0,0 +1,234 @@
#!/usr/bin/env bash
#
# Copyright 2021 Marco Vermeulen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# set env vars if not set
if [ -z "$SDKMAN_VERSION" ]; then
:
fi
if [ -z "$SDKMAN_CANDIDATES_API" ]; then
:
fi
if [ -z "$SDKMAN_DIR" ]; then
:
fi
# Load the sdkman config if it exists.
if [ -f "${SDKMAN_DIR}/etc/config" ]; then
source "${SDKMAN_DIR}/etc/config"
fi
# infer platform
function infer_platform() {
local kernel
local machine
kernel="$(uname -s)"
machine="$(uname -m)"
case $kernel in
Linux)
case $machine in
i686)
echo "LinuxX32"
;;
x86_64)
echo "LinuxX64"
;;
armv6l)
echo "LinuxARM32HF"
;;
armv7l)
echo "LinuxARM32HF"
;;
armv8l)
echo "LinuxARM32HF"
;;
aarch64)
echo "LinuxARM64"
;;
*)
echo "Exotic"
;;
esac
;;
Darwin)
case $machine in
x86_64)
echo "DarwinX64"
;;
arm64)
if [[ "$sdkman_rosetta2_compatible" == 'true' ]]; then
echo "DarwinX64"
else
echo "DarwinARM64"
fi
;;
*)
echo "DarwinX64"
;;
esac
;;
*)
echo "$kernel"
esac
}
SDKMAN_PLATFORM="$(infer_platform | tr '[:upper:]' '[:lower:]')"
:
# OS specific support (must be 'true' or 'false').
cygwin=false
darwin=false
solaris=false
freebsd=false
SDKMAN_KERNEL="$(uname -s)"
case "${SDKMAN_KERNEL}" in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
SunOS*)
solaris=true
;;
FreeBSD*)
freebsd=true
esac
# Determine shell
zsh_shell=false
bash_shell=false
if [[ -n "$ZSH_VERSION" ]]; then
zsh_shell=true
elif [[ -n "$BASH_VERSION" ]]; then
bash_shell=true
fi
# Source sdkman module scripts and extension files.
#
# Extension files are prefixed with 'sdkman-' and found in the ext/ folder.
# Use this if extensions are written with the functional approach and want
# to use functions in the main sdkman script. For more details, refer to
# <https://github.com/sdkman/sdkman-extensions>.
OLD_IFS="$IFS"
IFS=$'\n'
scripts=($(find "${SDKMAN_DIR}/src" "${SDKMAN_DIR}/ext" -type f -name 'sdkman-*.sh'))
for f in "${scripts[@]}"; do
source "$f"
done
IFS="$OLD_IFS"
unset OLD_IFS scripts f
# Create upgrade delay file if it doesn't exist
if [[ ! -f "${SDKMAN_DIR}/var/delay_upgrade" ]]; then
touch "${SDKMAN_DIR}/var/delay_upgrade"
fi
# set curl connect-timeout and max-time
if [[ -z "$sdkman_curl_connect_timeout" ]]; then sdkman_curl_connect_timeout=7; fi
if [[ -z "$sdkman_curl_max_time" ]]; then sdkman_curl_max_time=10; fi
# set curl retry
if [[ -z "${sdkman_curl_retry}" ]]; then sdkman_curl_retry=0; fi
# set curl retry max time in seconds
if [[ -z "${sdkman_curl_retry_max_time}" ]]; then sdkman_curl_retry_max_time=60; fi
# set curl to continue downloading automatically
if [[ -z "${sdkman_curl_continue}" ]]; then sdkman_curl_continue=true; fi
# read list of candidates and set array
SDKMAN_CANDIDATES_CACHE="${SDKMAN_DIR}/var/candidates"
SDKMAN_CANDIDATES_CSV=$(<"$SDKMAN_CANDIDATES_CACHE")
__sdkman_echo_debug "Setting candidates csv: $SDKMAN_CANDIDATES_CSV"
if [[ "$zsh_shell" == 'true' ]]; then
SDKMAN_CANDIDATES=(${(s:,:)SDKMAN_CANDIDATES_CSV})
else
IFS=',' read -a SDKMAN_CANDIDATES <<< "${SDKMAN_CANDIDATES_CSV}"
fi
:
for candidate_name in "${SDKMAN_CANDIDATES[@]}"; do
candidate_dir="${SDKMAN_CANDIDATES_DIR}/${candidate_name}/current"
if [[ -h "$candidate_dir" || -d "${candidate_dir}" ]]; then
:
:
fi
done
unset candidate_name candidate_dir
:
# source completion scripts
if [[ "$sdkman_auto_complete" == 'true' ]]; then
if [[ "$zsh_shell" == 'true' ]]; then
# initialize zsh completions (if not already done)
if ! (( $+functions[compdef] )) ; then
autoload -Uz compinit
if [[ $ZSH_DISABLE_COMPFIX == 'true' ]]; then
compinit -u -C
else
compinit
fi
fi
autoload -U bashcompinit
bashcompinit
source "${SDKMAN_DIR}/contrib/completion/bash/sdk"
__sdkman_echo_debug "ZSH completion script loaded..."
elif [[ "$bash_shell" == 'true' ]]; then
source "${SDKMAN_DIR}/contrib/completion/bash/sdk"
__sdkman_echo_debug "Bash completion script loaded..."
else
__sdkman_echo_debug "No completion scripts found for $SHELL"
fi
fi
if [[ "$sdkman_auto_env" == "true" ]]; then
if [[ "$zsh_shell" == "true" ]]; then
function sdkman_auto_env() {
if [[ -n $SDKMAN_ENV ]] && [[ ! $PWD =~ ^$SDKMAN_ENV ]]; then
sdk env clear
fi
if [[ -f .sdkmanrc ]]; then
sdk env
fi
}
chpwd_functions+=(sdkman_auto_env)
else
function sdkman_auto_env() {
if [[ -n $SDKMAN_ENV ]] && [[ ! $PWD =~ ^$SDKMAN_ENV ]]; then
sdk env clear
fi
if [[ "$SDKMAN_OLD_PWD" != "$PWD" ]] && [[ -f ".sdkmanrc" ]]; then
sdk env
fi
:
}
trimmed_prompt_command="${PROMPT_COMMAND%"${PROMPT_COMMAND##*[![:space:]]}"}"
[[ -z "$trimmed_prompt_command" ]] && PROMPT_COMMAND="sdkman_auto_env" || PROMPT_COMMAND="${trimmed_prompt_command%\;};sdkman_auto_env"
fi
sdkman_auto_env
fi

View File

@ -1,16 +0,0 @@
function battery --description "Print battery status"
if test (uname -s) != Darwin
echo "Unsupported kernel: "(uname -s)
else
set --local battery_status (pmset -g batt | string split0)
set --local battery_charge (echo $battery_status | rg --only-matching "\d+%")
set --local power_source (echo $battery_status | rg --only-matching "[A-Za-z]+\sPower")
set_color green
echo "⚡️ Running on $power_source with $battery_charge charge"
set_color normal
end
# Repaint is needed since there is a keybinding for this function
commandline -f repaint
end

View File

@ -1,12 +0,0 @@
# https://github.com/nickeb96/puffer-fish
function expand_dots -d 'Expand ... to ../..'
set -l item (string split ' ' (commandline --cut-at-cursor))[-1]
switch $item
case './*'
commandline --insert '.'
case '*..'
commandline --insert '/..'
case '*'
commandline --insert '.'
end
end

View File

@ -1,6 +1,6 @@
function fisher --argument-names cmd --description "A plugin manager for Fish" function fisher --argument-names cmd --description "A plugin manager for Fish"
set --query fisher_path || set --local fisher_path $__fish_config_dir set --query fisher_path || set --local fisher_path $__fish_config_dir
set --local fisher_version 4.4.3 set --local fisher_version 4.4.4
set --local fish_plugins $__fish_config_dir/fish_plugins set --local fish_plugins $__fish_config_dir/fish_plugins
switch "$cmd" switch "$cmd"
@ -13,8 +13,8 @@ function fisher --argument-names cmd --description "A plugin manager for Fish"
echo " fisher update Update all installed plugins" echo " fisher update Update all installed plugins"
echo " fisher list [<regex>] List installed plugins matching regex" echo " fisher list [<regex>] List installed plugins matching regex"
echo "Options:" echo "Options:"
echo " -v or --version Print version" echo " -v, --version Print version"
echo " -h or --help Print this help message" echo " -h, --help Print this help message"
echo "Variables:" echo "Variables:"
echo " \$fisher_path Plugin installation path. Default: $__fish_config_dir" | string replace --regex -- $HOME \~ echo " \$fisher_path Plugin installation path. Default: $__fish_config_dir" | string replace --regex -- $HOME \~
case ls list case ls list
@ -98,7 +98,7 @@ function fisher --argument-names cmd --description "A plugin manager for Fish"
echo Fetching (set_color --underline)\$url(set_color normal) echo Fetching (set_color --underline)\$url(set_color normal)
if curl --silent -L \$url | tar -xzC \$temp -f - 2>/dev/null if command curl -q --silent -L \$url | command tar -xzC \$temp -f - 2>/dev/null
command cp -Rf \$temp/*/* $source command cp -Rf \$temp/*/* $source
else else
echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2 echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2

View File

@ -1,3 +1,9 @@
# Wrapper function for SDKMAN!
# Copyright (c) 2018-2023 Raphael Reitzig
# MIT License (MIT)
# https://github.com/reitzig/sdkman-for-fish
function sdk -d "Manage SDKs" function sdk -d "Manage SDKs"
# Guard: SDKMAN! needs to be installed # Guard: SDKMAN! needs to be installed
if not test -f "$__fish_sdkman_init" if not test -f "$__fish_sdkman_init"

View File

@ -35,13 +35,12 @@
plus-emph-style = bold green 22 plus-emph-style = bold green 22
zero-style = dim syntax zero-style = dim syntax
[diff] [diff]
algorithm = histogram
colorMoved = default colorMoved = default
[interactive] [interactive]
diffFilter = delta --color-only diffFilter = delta --color-only
[log] [log]
date = human date = human
[merge]
conflictStyle = zdiff3
[pull] [pull]
rebase = true rebase = true
[push] [push]

View File

@ -5,6 +5,7 @@
with import <nixpkgs> {}; [ with import <nixpkgs> {}; [
bat bat
delta delta
direnv
duf duf
du-dust du-dust
fd fd
@ -15,6 +16,7 @@ with import <nixpkgs> {}; [
git-repo-updater git-repo-updater
helix helix
jq jq
just
less less
macchina macchina
nix nix