Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to fishtape 3 #275

Merged
merged 31 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
432c3ef
correct typo
edouard-lopez Jan 13, 2021
6d093f8
use (status filename) instead of $current_filename
edouard-lopez Jan 13, 2021
27a7bc4
Use (dirname (status filename)) instead of $current_dirname (needs Fi…
edouard-lopez Jan 13, 2021
5a61d20
replace `@mesg` by `@echo`
edouard-lopez Jan 13, 2021
027c7c6
explicit call to `setup` and `teardown`
edouard-lopez Jan 13, 2021
fd39dff
default dev version is Fish 3.3.1
edouard-lopez Nov 18, 2021
cc01a4f
chore: remove non-existing --quiet option in `docker run`
edouard-lopez May 17, 2022
9968aed
test: fix _pure_prompt_first_line.test
edouard-lopez May 17, 2022
bc2911d
docs: improve some function descriptions
edouard-lopez May 19, 2022
8c05419
chore: lint
edouard-lopez May 19, 2022
8b605ad
test: fix _pure_prompts tests
edouard-lopez May 19, 2022
244ca08
test: isolate git related tests
edouard-lopez May 19, 2022
4cd0591
fix: support other container runtimes (cf. #290)
edouard-lopez May 23, 2022
c63f63a
bump version 4.1.2
edouard-lopez May 23, 2022
3c2732f
test: use `builtin` command to call builtin instead of workaround
edouard-lopez May 29, 2022
8f13484
test: fix _pure_prompt_vimode.test.fish
edouard-lopez Jun 20, 2022
4f46656
ci: remove duplicate matrix entry
edouard-lopez Jun 20, 2022
83f7b42
test: fix _pure_prompt_virtualenv.test.fish
edouard-lopez Jun 20, 2022
e4d8313
test: fix fish_greeting.test.fish
edouard-lopez Jul 1, 2022
67b728b
test: fix fish_prompt.test.fish
edouard-lopez Jul 1, 2022
a351dce
test: fix migration-to-4.0.0.test.fish
edouard-lopez Jul 1, 2022
cf729fc
test: fix pure_tools_installer.test.fish
edouard-lopez Sep 24, 2022
d79adbc
test: fix sourcing error in tools/version-compare.fish
edouard-lopez Sep 24, 2022
4063a03
ci: remove EOL versoin 3.0.2
edouard-lopez Sep 24, 2022
fd7dc7c
test: support 3.1.2 and ≥3.3.0 vi_mode colors
edouard-lopez Sep 24, 2022
29e697e
test: fix _pure_prompt_container
edouard-lopez Sep 24, 2022
387a37b
ci: print fish version on MacOS
edouard-lopez Oct 6, 2022
1302f64
ci: select specific version to install on macOS
edouard-lopez Oct 6, 2022
8fca28b
ci: remove MacOS job
edouard-lopez Oct 6, 2022
f29672e
ci: add 3.5.x and 3.4.1 version to matrix
edouard-lopez Oct 6, 2022
0d0a41c
ci: focus on 3.1.2 and 3.3.1 for now so we can merge
edouard-lopez Oct 6, 2022
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
17 changes: 2 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,11 @@ jobs:
strategy:
matrix:
fish_version:
- "3.3.1"
- "3.1.2"
- "3.1.0"
- "3.0.2"
steps:
- uses: actions/checkout@v2
- run: make build-pure-on FISH_VERSION=${{ matrix.fish_version }}
- run: docker --version
- run: make test-pure-on FISH_VERSION=${{ matrix.fish_version }}

test-macos:
name: Test on fish on MacOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Install Fish
run: brew install fish
- name: Install Fisher > Fishtape > Pure
run: curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher jorgebucaran/fishtape ./
shell: fish {0}
- name: Test Pure
run: fishtape tests/*.test.fish
shell: fish {0}
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,26 @@ You can tweak `pure` behavior and color by changing [universal variables](https:

> :warning: The absence of `$` sign is expected in `pure_` named colours.

| Base Color | Inherited by | Default |
| :----------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------- |
| **`pure_color_danger`** | **`pure_color_prompt_on_error`** | `red` |
| **`pure_color_dark`** | | `black` |
| **`pure_color_info`** | **`pure_color_git_unpulled_commits`**<br>**`pure_color_git_unpushed_commits`** | `cyan` |
| **`pure_color_light`** | **`pure_color_username_root`** | `white` |
| Base Color | Inherited by | Default |
| :----------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------- |
| **`pure_color_danger`** | **`pure_color_prompt_on_error`** | `red` |
| **`pure_color_dark`** | | `black` |
| **`pure_color_info`** | **`pure_color_git_unpulled_commits`**<br>**`pure_color_git_unpushed_commits`** | `cyan` |
| **`pure_color_light`** | **`pure_color_username_root`** | `white` |
| **`pure_color_mute`** | **`pure_color_git_branch`**<br>**`pure_color_git_dirty`**<br>**`pure_color_git_stash`**<br>**`pure_color_hostname`**<br>**`pure_color_at_sign`**<br>**`pure_color_username_normal`**<br>**`pure_color_virtualenv`** | `brblack` |
| **`pure_color_normal`** | **`pure_color_jobs`** | `normal` |
| **`pure_color_primary`** | **`pure_color_current_directory`** | `blue` |
| **`pure_color_success`** | **`pure_color_prompt_on_success`** | `magenta` |
| **`pure_color_warning`** | **`pure_color_command_duration`** | `yellow` |
| **`pure_color_normal`** | **`pure_color_jobs`** | `normal` |
| **`pure_color_primary`** | **`pure_color_current_directory`** | `blue` |
| **`pure_color_success`** | **`pure_color_prompt_on_success`** | `magenta` |
| **`pure_color_warning`** | **`pure_color_command_duration`** | `yellow` |

## :+1: Contribute

> **requirements:** [`docker`](https://docs.docker.com/install/) (isolate from your environment)

Specify the [`FISH_VERSION`][fish-releases] you want, and the `CMD` executed by the container:

make build-pure-on FISH_VERSION=3.1.2
make dev-pure-on FISH_VERSION=3.1.2 CMD="fishtape tests/*.test.fish"
make build-pure-on FISH_VERSION=3.3.1
make dev-pure-on FISH_VERSION=3.3.1 CMD="fishtape tests/*.test.fish"

## :man_technologist: Maintainer

Expand Down
2 changes: 1 addition & 1 deletion conf.d/pure.fish
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set --global pure_version 4.1.1 # For bug report and tag-after-merge workflow
set --global pure_version 4.1.2 # For bug report and tag-after-merge workflow

# Base colors
_pure_set_default pure_color_primary blue
Expand Down
11 changes: 11 additions & 0 deletions functions/_pure_detect_container_by_cgroup_method.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function _pure_detect_container_by_cgroup_method \
--description "Linux method to detect container using cgroup. see https://stackoverflow.com/a/37015387/802365" \
--argument-names cgroup_namespace
set --query cgroup_namespace[1]; or set cgroup_namespace /proc/1/cgroup

# echo "cgroup_namespace: $cgroup_namespace"
string match \
--quiet \
--entire \
--regex '(lxc|docker)' <$cgroup_namespace
end
11 changes: 11 additions & 0 deletions functions/_pure_detect_container_by_pid_method.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function _pure_detect_container_by_pid_method \
--description "Linux method to detect container using /proc. see https://stackoverflow.com/a/37015387/802365"

set --query proc_sched[1]; or set proc_sched /proc/1/sched

head -n 1 $proc_sched \
| string match \
--quiet \
--invert \
--regex 'init|systemd'
end
32 changes: 23 additions & 9 deletions functions/_pure_is_inside_container.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@ function _pure_is_inside_container \
--argument-names cgroup_namespace
set --query cgroup_namespace[1]; or set cgroup_namespace /proc/1/cgroup

begin
test -r $cgroup_namespace
and string match \
--quiet \
--entire \
--regex '(lxc|docker)' \
<$cgroup_namespace
end
or test "$container" = "lxc"
function _pure_detect_container_by_pid_method # see https://stackoverflow.com/a/37015387/802365
head -n 1 /proc/1/sched \
| string match \
--quiet \
--invert \
--regex 'init|systemd'
end

set --local success 0
if test -n "$container"
return $success
end

if _pure_detect_container_by_pid_method
return $success
end

if _pure_detect_container_by_cgroup_method $cgroup_namespace
return $success
end

set --local failure 1
return $failure
end
4 changes: 3 additions & 1 deletion functions/_pure_print_prompt.fish
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function _pure_print_prompt
function _pure_print_prompt \
--description 'Concatenate parts single prompt string' \

set --local prompt

for prompt_part in $argv
Expand Down
17 changes: 9 additions & 8 deletions functions/_pure_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ function _pure_prompt \
set --local system_time (_pure_prompt_system_time)
set --local root_prefix (_pure_prefix_root_prompt)
set --local space

if _pure_is_single_line_prompt
set space ' '
end

echo (\
_pure_print_prompt \
$system_time \
$root_prefix \
$jobs \
$virtualenv \
$vimode_indicator \
$space \
$pure_symbol \
_pure_print_prompt \
$system_time \
$root_prefix \
$jobs \
$virtualenv \
$vimode_indicator \
$space \
$pure_symbol \
)
end
2 changes: 2 additions & 0 deletions functions/_pure_prompt_container.fish
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function _pure_prompt_container
_pure_is_inside_container
echo _pure_is_inside_container $status
if _pure_is_inside_container
echo (_pure_user_at_host)
end
Expand Down
5 changes: 3 additions & 2 deletions functions/_pure_prompt_vimode.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function _pure_prompt_vimode
if set --query pure_reverse_prompt_symbol_in_vimode; and test "$pure_reverse_prompt_symbol_in_vimode" = false
echo (fish_default_mode_prompt)
if set --query pure_reverse_prompt_symbol_in_vimode;
and test "$pure_reverse_prompt_symbol_in_vimode" = false
echo (fish_default_mode_prompt)
end
end
4 changes: 2 additions & 2 deletions functions/_pure_user_at_host.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ function _pure_user_at_host
set --local hostname_color (_pure_set_color $pure_color_hostname)

set --local username_color (_pure_set_color $pure_color_username_normal) # default color
if test "$username" = "root"
if test "$username" = root
set username_color (_pure_set_color $pure_color_username_root) # different color for root
end

echo "$username_color$username$at_sign_color$at_sign$hostname_color$hostname"
echo "2<$username_color$username$at_sign_color$at_sign$hostname_color$hostname>2"
end
11 changes: 6 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ INTERACTIVE=true
default: usage
usage:
@printf "usage:"
@printf "\tmake build-pure-on FISH_VERSION=3.1.2\t# build container\n"
@printf "\tmake test-pure-on FISH_VERSION=3.1.2\t# run tests\n"
@printf "\tmake dev-pure-on FISH_VERSION=3.1.2\t# dev in container\n"
@printf "\tmake build-pure-on FISH_VERSION=3.3.1\t# build container\n"
@printf "\tmake test-pure-on FISH_VERSION=3.3.1\t# run tests\n"
@printf "\tmake dev-pure-on FISH_VERSION=3.3.1\t# dev in container\n"

.PHONY: build-pure-on
build-pure-on:
docker build \
--quiet \
--quiet \
--file ./Dockerfile \
--build-arg FISH_VERSION=${FISH_VERSION} \
--tag=pure-on-fish-${FISH_VERSION} \
Expand All @@ -25,14 +25,15 @@ build-pure-on:
.PHONY: dev-pure-on
dev-pure-on: CMD?=fish
dev-pure-on:
chmod o=rwx tests/fixtures/ # for migration-to-4.0.0.test.fish only
docker run \
--quiet \
--name run-pure-on-${FISH_VERSION} \
--rm \
--interactive \
--tty \
--volume=$$(pwd):/tmp/.pure/ \
pure-on-fish-${FISH_VERSION} "${CMD}"
chmod o=r-x tests/fixtures/ # for migration-to-4.0.0.test.fish only

# Don't override COPY directive as `--volume` doesnt play nice with Travis
.PHONY: test-pure-on
Expand Down
49 changes: 49 additions & 0 deletions tests/_detect_container_by_cgroup_method.test.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
source (dirname (status filename))/fixtures/constants.fish
source (dirname (status filename))/../functions/_pure_detect_container_by_cgroup_method.fish
@echo (_print_filename (status filename))


function setup
_purge_configs
_disable_colors

set --global cgroup_namespace /tmp/proc/1/cgroup
set --global namespace (dirname $cgroup_namespace)
mkdir -p $namespace; and touch $cgroup_namespace
end
setup

function teardown
rm -rf \
$namespace \
$cgroup_namespace
set --erase cgroup_namespace
set --erase namespace
end

@test "_pure_detect_container_by_cgroup_method: false for host OS" (
echo "1:name=systemd:/init.scope" > $cgroup_namespace
set --global container $EMPTY

_pure_detect_container_by_cgroup_method $cgroup_namespace
) $status -eq $FAILURE

@test "_pure_detect_container_by_cgroup_method: true for Docker's container" (
echo "1:name=systemd:/docker/54c541…af18c609c" > $cgroup_namespace

_pure_detect_container_by_cgroup_method $cgroup_namespace
) $status -eq $SUCCESS

@test "_pure_detect_container_by_cgroup_method: true for LXC/LXD's container (using namespace detail)" (
echo "1:name=systemd:/lxc/54c541…af18c609c" > $cgroup_namespace

_pure_detect_container_by_cgroup_method $cgroup_namespace
) $status -eq $SUCCESS

@test "_pure_detect_container_by_cgroup_method: true for LXC/LXD's container (using environment variable)" (
set --global container 'lxc'

_pure_detect_container_by_cgroup_method $cgroup_namespace
) $status -eq $SUCCESS

teardown
Loading