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

upperstack reset bug fixed #43

Merged
merged 2 commits into from
Jan 18, 2025
Merged
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default: bash_interactive
bash_interactive:
docker-compose -f testenv/shellenv/bashenv/docker-compose.yaml build
docker-compose -f testenv/shellenv/bashenv/docker-compose.yaml run --rm fasttravelcli_bash_interactive
docker-compose -f testenv/shellfuncs/bashenv/docker-compose.yaml build
docker-compose -f testenv/shellfuncs/bashenv/docker-compose.yaml run --rm fasttravelcli_bash_interactive

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ bash install/linux.sh
```
bash install/mac.sh
```
Currently available for Unix-like OS and bash/zsh shells. May work in more shell environments but not guaranteed.

<h2>Disclaimers</h2>
Currently available for Unix-like OS and bash/zsh shells. May work in more shell environments but not guaranteed.
<br>
Compiles using go version >= 1.20.0, may work with older versions but not guaranteed.
<br>
Some features have dependencies.
- `-hist` requires tree and [fzf](/~https://github.com/junegunn/fzf).

For some features, like the `-hist` command, [fzf](/~https://github.com/junegunn/fzf) is a dependency.



Expand Down
35 changes: 19 additions & 16 deletions shells/bash/ftmain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,40 @@

ft__check_fzf() {
if ! command -v fzf &>/dev/null; then
echo "Error: fzf is needed to use this feature. You can install it using your package manager:"
echo " - Ubuntu/Debian: sudo apt install fzf"
echo " - Fedora: sudo dnf install fzf"
echo " - Arch: sudo pacman -S fzf"
echo " - macOS: brew install fzf"
echo "Error: fzf is needed to use this feature. /~https://github.com/junegunn/fzf"
return 1
fi
}

ft__check_tree() {
if ! command -v tree &>/dev/null; then
echo "Error: tree is needed to use this feature. You can install it using your package manager:"
echo " - Ubuntu/Debian: sudo apt install tree"
echo " - Fedora: sudo dnf install tree"
echo " - Arch: sudo pacman -S tree"
echo " - macOS: brew install tree"
return 1
fi
}

ft__upperStack=()

ft__pushup() {
local _path="$1"
ft__upperStack+=("$_path")
local path="$1"
ft__upperStack+=("$path")
}

ft__popup() {
unset 'ft__upperStack[-1]'
ft__upperStack=(${ft_upperStack[@]})
ft__upperStack=(${ft__upperStack[@]})
}

ft__capture() {
local temp_output=$(mktemp)

"$FT_EXE_PATH" "$@" | tee "$temp_output"
local output="$(tail -n 1 "$temp_output")"
rm "$temp_output"

echo "$output"
}
Expand All @@ -46,7 +54,6 @@ ft__execute() {

if [ ${#ft__upperStack[@]} -eq 0 ]; then
echo Already at head of history stack.
rm "$temp_output"
return 1
fi

Expand All @@ -60,7 +67,6 @@ ft__execute() {

if [ "$lowerStackLen" -eq 0 ]; then
echo Already at tail of history stack.
rm "$temp_output"
return 1
fi

Expand All @@ -70,6 +76,7 @@ ft__execute() {

elif [[ "$output" == "hist" ]]; then
ft__check_fzf
ft__check_tree

local navigation="up;"
for i in "${ft__upperStack[@]}"; do
Expand All @@ -81,18 +88,14 @@ ft__execute() {
local historyStack=("${ft__upperStack[@]}" "${lowerStack[@]}")

local selected=$(printf "%s\n" "${historyStack[@]}" | fzf \
--bind "start:execute-silent($navigation)")
--tac --header "Currently at $(pwd)" --preview 'tree {}')

if [[ -n "$selected" ]]; then
pushd "$selected" > /dev/null || echo "Could not find directory $selected"
fi
else
echo "$full_output"
fi

if [[ -f "$temp_output" ]]; then
rm "$temp_output"
fi
fi

}

Expand Down
10 changes: 7 additions & 3 deletions shells/tests/bashscripts/commands.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

test_create_project_tree() {
maketree() {
mkdir something
cd something
mkdir else
Expand All @@ -9,11 +9,15 @@ test_create_project_tree() {
cd ../../..
}

available_commands=("]" "[" "-hist" ".." "-")
maketree

test_cmd() {
available_commands=("]" "[" "hist" ".." "-")

testcmd() {
local selected=$(printf "%s\n" "${available_commands[@]}" | fzf)
if [[ -n "$selected" ]]; then
ft__execute "$selected"
fi
}


8 changes: 1 addition & 7 deletions shells/tests/bashscripts/test.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
-- TODO:
-- - Docker container that:
-- - sources appropriate .sh file
-- - runs test script
-- - set up interactive container as well for manual testing
-- - Lua (or Python) script that:
-- - mocks input to ft function for all passToShell commands
-- - verify correct functionality
-- - write tests for each ft__ function
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ COPY ../../../shells/bash/ ./
RUN apt-get update && apt-get install -y \
git \
curl \
tree \
&& rm -rf /var/lib/apt/lists/*

# Install fzf
Expand All @@ -23,13 +24,10 @@ RUN git clone --depth 1 /~https://github.com/junegunn/fzf.git ~/.fzf && \
# Set up fzf in the shell
RUN echo 'source ~/.fzf.bash' >> ~/.bashrc

# Source scripts to run test
# Source scripts used to run tests
RUN echo 'source commands.sh' >> ~/.bashrc

RUN echo 'source ftmain.sh' >> ~/.bashrc

# Build a project tree
RUN test_create_project_tree

CMD ["/bin/bash"]

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
fasttravelcli_bash_interactive:
build:
context: ../../..
dockerfile: testenv/shellenv/bashenv/Dockerfile
dockerfile: testenv/shellfuncs/bashenv/Dockerfile
container_name: fasttravelcli_bash_interactive
stdin_open: true
tty: true
Expand Down
Loading