Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions .github/workflows/ci.yml

This file was deleted.

117 changes: 117 additions & 0 deletions .github/workflows/devel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: devel

on: [push, pull_request]

env:
# Test framework: https://github.com/joseluisq/fishtest (pinned)
FISHTEST_REF: v0.0.1

jobs:
lint:
name: Lint (fish 4)
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install fish 4
run: |
sudo add-apt-repository -y ppa:fish-shell/release-4
sudo apt-get update -qq
sudo apt-get install -y fish
fish --version
# fish -n checks a single script per invocation (extra arguments
# become $argv), so each file gets its own call.
- name: Syntax check
shell: bash -O globstar -e {0}
run: |
for f in conf.d/*.fish functions/*.fish completions/*.fish testing/*.fish tests/**/*.fish; do
fish --no-execute "$f" || exit 1
done
# Advisory until Phase 3 lands canonical fish_indent formatting;
# drop `continue-on-error` there so formatting drift blocks merge.
- name: Format check (advisory)
continue-on-error: true
run: fish_indent --check conf.d/*.fish functions/*.fish completions/*.fish

test:
name: Test suite (fish 4, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-24.04
- macos-14
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install fish 4
run: |
if [ "${{ matrix.os }}" = "ubuntu-24.04" ]; then
sudo add-apt-repository -y ppa:fish-shell/release-4
sudo apt-get update -qq
sudo apt-get install -y fish
elif [ "${{ matrix.os }}" = "macos-14" ]; then
brew install fish
fi
fish --version
- name: Install FishTest
run: |
git clone --quiet --depth 1 --branch "$FISHTEST_REF" https://github.com/joseluisq/fishtest.git "$RUNNER_TEMP/fishtest"
"$RUNNER_TEMP/fishtest/bin/fishtest" --version
- name: Run test suite
run: '"$RUNNER_TEMP/fishtest/bin/fishtest" --color tests'
- name: Startup profile (informational)
run: |
fish --profile "$RUNNER_TEMP/gitnow.prof" -c 'set -g fish_snippets $PWD/conf.d; source conf.d/gitnow.fish'
sort -nrk 2 "$RUNNER_TEMP/gitnow.prof" | head -n 15

# TODO(phase-3): once the Fish >= 4.0 startup guard lands, add a minimal
# Fish 3.x job asserting that sourcing conf.d prints the guard message
# cleanly and defines nothing.

paket:
name: Paket install and test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install and test
uses: addnab/docker-run-action@v3
with:
image: joseluisq/paket
options: -v ${{ github.workspace }}:/gitnow
shell: fish
run: |
fish --version
paket --version
git config --global --add safe.directory /gitnow
paket add joseluisq/fishtest
paket add /gitnow
/gitnow/testing/test.fish
cd /gitnow
fishtest --color tests

fisher:
name: Fisher install and test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install and test
uses: addnab/docker-run-action@v3
with:
image: joseluisq/paket
options: -v ${{ github.workspace }}:/gitnow
shell: fish
run: |
apk add --no-cache curl git
fish --version
curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source
fisher --version
git config --global --add safe.directory /gitnow
fisher install joseluisq/fishtest
fisher install /gitnow
/gitnow/testing/test.fish
cd /gitnow
fishtest --color tests
15 changes: 7 additions & 8 deletions conf.d/gitnow.fish
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if set -q __fish_config_dir
else
set -q XDG_CONFIG_HOME
and set -g fish_config "$XDG_CONFIG_HOME/fish"
or set -g fish_config "~/.config/fish"
or set -g fish_config "$HOME/.config/fish"
end

set -q fish_snippets; or set -g fish_snippets "$fish_config/conf.d"
Expand All @@ -31,6 +31,10 @@ function __gitnow_uninstall -e gitnow_uninstall
echo "GitNow was uninstalled successfully."
end

function __gitnow_update -e gitnow_update
echo (gitnow -v)" is updated and ready to use!"
end

function gitnow -d "Gitnow: Speed up your Git workflow. 🐠" -a xversion
if [ "$xversion" = "-v" ]; or [ "$xversion" = "--version" ]
echo "GitNow version $gitnow_version"
Expand Down Expand Up @@ -197,8 +201,6 @@ function push -d "Gitnow: Push commit changes to remote repository" -w 'git push
echo "Remote URL: $xorigin ($xremote_url)"
echo "Remote branch: $xbranch"
else
set -l v_mode "auto"

for v in $argv
switch $v
case -t --tags
Expand All @@ -218,7 +220,6 @@ function push -d "Gitnow: Push commit changes to remote repository" -w 'git push
return
case -\*
case '*'
set -l v_mode "manual"
echo "Mode: Manual"
end
end
Expand Down Expand Up @@ -436,8 +437,6 @@ function move -d "GitNow: Switch from current branch to another but stashing unc
return
end

set -l v_fetched 0

# Fetch branch from remote
if test -n "$v_upstream"
echo "Switching to the specified remote branch."
Expand All @@ -458,7 +457,7 @@ function move -d "GitNow: Switch from current branch to another but stashing unc
set -l v_found (__gitnow_check_if_branch_exist $v_branch)

# Branch was not found
if begin test $v_found -eq 0; and test $v_fetched -eq 0; end
if test $v_found -eq 0
echo "Branch `$v_branch` was not found locally. No possible to switch."
echo "Tip: Use -u (--upstream) flag to fetch a remote branch."
return
Expand Down Expand Up @@ -666,7 +665,7 @@ function tag -d "Gitnow: Tag commits following Semver"
if test -n "$v_patch"
if not test -n "$v_latest"
command git tag $opts v0.0.1
echo "First patch tag \"v0.1.0\" was created."
echo "First patch tag \"v0.0.1\" was created."
return
else
set -l vstr (__gitnow_get_valid_semver_release_value $v_latest)
Expand Down
30 changes: 23 additions & 7 deletions functions/__gitnow_check_create_branch.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,33 @@
# https://github.com/joseluisq/gitnow

function __gitnow_check_create_branch -a xbranch
if test -z "$xbranch"
echo "Branch name is required."
return
end

set xbranch (__gitnow_slugify $xbranch)

if test -z "$xbranch"
echo "Branch name is required."
return
end

set -l xfound (__gitnow_check_if_branch_exist $xbranch)

if test -n "$xbranch"
if test $xfound -eq 1
echo "Branch `$xbranch` already exists. Nothing to do."
else
if test $xfound -eq 1
echo "Branch `$xbranch` already exists. Nothing to do."
else
set -l v_uncommited (__gitnow_has_uncommited_changes)

if test -n "$v_uncommited"
command git stash
__gitnow_new_branch_switch "$xbranch"
end

__gitnow_new_branch_switch "$xbranch"

if test -n "$v_uncommited"
command git stash pop
end
else
echo "Branch name is required."
end
end
7 changes: 5 additions & 2 deletions functions/__gitnow_current_branch_list.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# GitNow — Speed up your Git workflow. 🐠
# https://github.com/joseluisq/gitnow

function __gitnow_current_branch_list
command git branch --list --no-color | LC_ALL=C command sed -E "s/^(\*?[ \t]*)//g" 2>/dev/null
function __gitnow_current_branch_list -d "Lists local branch names, one per line"
# Ask git for clean names instead of parsing `git branch` output: no
# `*` marker, no padding, no "(HEAD detached at ...)" line — and no
# sed, whose `\t` handling differs between GNU and BSD (macOS).
command git for-each-ref --format='%(refname:short)' refs/heads/ 2>/dev/null
end
8 changes: 4 additions & 4 deletions functions/__gitnow_get_clip_program.fish
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
function __gitnow_get_clip_program -d "Gets the current clip installed program"
set -l v_paste

if type -q xclip
if command -q xclip
set v_paste "xclip -selection clipboard -o"
else if type -q wl-clipboard
else if command -q wl-paste
set v_paste "wl-paste"
else if type -q xsel
else if command -q xsel
set v_paste "xsel --clipboard --output"
else if type -q pbpaste
else if command -q pbpaste
set v_paste "pbpaste"
end

Expand Down
4 changes: 2 additions & 2 deletions functions/__gitnow_get_latest_semver_release_tag.fish
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

function __gitnow_get_latest_semver_release_tag
for tg in (__gitnow_get_tags_ordered)
if echo $tg | LC_ALL=C command grep -qE '^v?([0-9]+).([0-9]+).([0-9]+)$'
echo $tg 2>/dev/null
if string match -qr '^v?\d+\.\d+\.\d+$' -- $tg
echo $tg
break
end
end
Expand Down
6 changes: 0 additions & 6 deletions functions/__gitnow_get_latest_tag.fish

This file was deleted.

2 changes: 1 addition & 1 deletion functions/__gitnow_get_valid_semver_release_value.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# https://github.com/joseluisq/gitnow

function __gitnow_get_valid_semver_release_value -a tagv
command echo $tagv | LC_ALL=C command sed -n 's/^v\\{0,1\\}\([0-9].[0-9].[0-9]*\)\([}]*\)/\1/p' 2>/dev/null
string match -rg '^v?(\d+\.\d+\.\d+)' -- $tagv
end
12 changes: 10 additions & 2 deletions functions/__gitnow_gitflow_branch.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ function __gitnow_gitflow_branch -a xprefix -a xbranch
if test $xfound -eq 1
echo "Branch `$xbranch_full` already exists. Nothing to do."
else
command git stash
set -l v_uncommited (__gitnow_has_uncommited_changes)

if test -n "$v_uncommited"
command git stash
end

__gitnow_new_branch_switch "$xbranch_full"
command git stash pop

if test -n "$v_uncommited"
command git stash pop
end
end
end
6 changes: 5 additions & 1 deletion functions/__gitnow_has_uncommited_changes.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
# https://github.com/joseluisq/gitnow

function __gitnow_has_uncommited_changes
command git diff-index --quiet HEAD -- || echo "1" 2>&1
# Refresh stat-only differences first so a touched-but-unchanged file
# doesn't report as dirty (a no-op `git stash` followed by `git stash pop`
# would pop an older, unrelated stash entry).
command git update-index -q --refresh 2>/dev/null
command git diff-index --quiet HEAD -- 2>/dev/null; or echo "1"
end
2 changes: 1 addition & 1 deletion functions/__gitnow_load_config.fish
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function __gitnow_load_config -d "Reads the GitNow configuration file"
case 'release' 'hotfix' 'feature' 'bugfix'
# Read text from clipboard if there is a valid clipboard program
# and if the "clipboard" option is "true"
if test -n $g_xpaste; and test $v_clipboard -eq 1
if test -n "$g_xpaste"; and test $v_clipboard -eq 1
set cmd (echo -n "bind \\$v_command_val \"echo; if $v_command_key ($g_xpaste); commandline -f repaint; else ; end\"")
else
# Otherwise read text from standard input
Expand Down
23 changes: 20 additions & 3 deletions functions/__gitnow_slugify.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
# GitNow — Speed up your Git workflow. 🐠
# https://github.com/joseluisq/gitnow

# adapted from https://gist.github.com/oneohthree/f528c7ae1e701ad990e6
function __gitnow_slugify
echo $argv | LC_ALL=C command iconv -t ascii//TRANSLIT | LC_ALL=C command sed -E 's/[^a-zA-Z0-9\-]+/_/g' | LC_ALL=C command sed -E 's/^(-|_)+|(-|_)+$//g'
function __gitnow_slugify -d "Turns free text into a git-safe, lowercase branch slug"
# Pure Fish, no iconv: `iconv //TRANSLIT` is GNU-only in practice (macOS
# iconv rejects or drops accented characters). Transliterate the common
# Latin accents by hand, lowercase, then map anything else non-ASCII to
# `_`. `/` and `.` are preserved since they are valid in branch names.
set -l s (string join ' ' -- $argv)

set s (string replace -ra '[àáâäãåāÀÁÂÄÃÅĀ]' a -- $s)
set s (string replace -ra '[èéêëēÈÉÊËĒ]' e -- $s)
set s (string replace -ra '[ìíîïīÌÍÎÏĪ]' i -- $s)
set s (string replace -ra '[òóôöõøōÒÓÔÖÕØŌ]' o -- $s)
set s (string replace -ra '[ùúûüūÙÚÛÜŪ]' u -- $s)
set s (string replace -ra '[ýÿÝŸ]' y -- $s)
set s (string replace -ra '[ñÑ]' n -- $s)
set s (string replace -ra '[çÇ]' c -- $s)
set s (string replace -ra '[ß]' ss -- $s)
set s (string replace -ra '[æÆ]' ae -- $s)
set s (string replace -ra '[œŒ]' oe -- $s)

string lower -- $s | string replace -ra '[^a-z0-9./-]+' '_' | string replace -ra '^[-_./]+|[-_./]+$' ''
end
4 changes: 3 additions & 1 deletion testing/test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

echo "Testing GitNow files..."

set -l out (fish -c 'source' 2>&1)
# `source` with no args reads stdin — close it explicitly or this blocks
# forever when the caller keeps stdin open (e.g. some CI runners).
set -l out (fish -c 'source' < /dev/null 2>&1)

if test $status -gt 0
echo "ERROR: Fish shell error signal was emitted!"
Expand Down
Loading
Loading