Skip to content

Commit 198cdb9

Browse files
authored
Installing and upgrading (#757)
1 parent 6984550 commit 198cdb9

14 files changed

Lines changed: 175 additions & 55 deletions

.github/workflows/release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ jobs:
109109
needs: [create-release, build-release]
110110
runs-on: ubuntu-latest
111111
steps:
112+
- name: Checkout
113+
uses: actions/checkout@v7
114+
- name: Upload install.sh to release
115+
env:
116+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
run: |
118+
gh release upload "${{ needs.create-release.outputs.version }}" install.sh --clobber
112119
- name: Mark release as prerelease
113120
env:
114121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -125,6 +132,6 @@ jobs:
125132
uses: docker/setup-buildx-action@v4
126133
- name: Test installation on Alpine and Ubuntu
127134
env:
128-
FLYLINE_RELEASE_VERSION: ${{ needs.create-release.outputs.version }}
135+
FLYLINE_INSTALL_VERSION: ${{ needs.create-release.outputs.version }}
129136
run: |
130137
docker buildx bake -f docker-bake.hcl install-test-alpine install-test-ubuntu install-test-bash-3-2-57

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Flyline is similar to [ble.sh](https://github.com/akinomyoga/ble.sh) but is writ
4444
> [!TIP]
4545
> Run the following command to download flyline and update your `.bashrc` to load the latest version. No need for `sudo`!
4646
```bash
47-
curl -sSfL https://raw.githubusercontent.com/HalFrgrd/flyline/master/install.sh | sh
47+
curl -sSfL https://github.com/HalFrgrd/flyline/releases/latest/download/install.sh | sh
4848
```
4949

5050

docker-bake.hcl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ variable "PRE_BASH_4_4_VERSION_MATRIX" {
66
default = ["3.2.57"]
77
}
88

9-
variable "FLYLINE_RELEASE_VERSION" {
9+
variable "FLYLINE_INSTALL_VERSION" {
1010
default = null
1111
}
1212

@@ -231,15 +231,15 @@ target "install-test-alpine" {
231231
context = "."
232232
dockerfile = "docker/install_test_alpine.Dockerfile"
233233
args = {
234-
FLYLINE_RELEASE_VERSION = FLYLINE_RELEASE_VERSION
234+
FLYLINE_INSTALL_VERSION = FLYLINE_INSTALL_VERSION
235235
}
236236
}
237237

238238
target "install-test-ubuntu" {
239239
context = "."
240240
dockerfile = "docker/install_test_ubuntu.Dockerfile"
241241
args = {
242-
FLYLINE_RELEASE_VERSION = FLYLINE_RELEASE_VERSION
242+
FLYLINE_INSTALL_VERSION = FLYLINE_INSTALL_VERSION
243243
}
244244
}
245245

@@ -250,7 +250,7 @@ target "install-test-bash-3-2-57" {
250250
}
251251
dockerfile = "docker/install_test_bash_3.2.57.Dockerfile"
252252
args = {
253-
FLYLINE_RELEASE_VERSION = FLYLINE_RELEASE_VERSION
253+
FLYLINE_INSTALL_VERSION = FLYLINE_INSTALL_VERSION
254254
}
255255
}
256256

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
FROM alpine:latest
22

3-
ARG FLYLINE_RELEASE_VERSION
3+
ARG FLYLINE_INSTALL_VERSION
44

55
RUN apk add --no-cache gcc bash curl
66

7-
RUN curl -sSfL https://raw.githubusercontent.com/HalFrgrd/flyline/master/install.sh | FLYLINE_RELEASE_VERSION=${FLYLINE_RELEASE_VERSION} sh
7+
RUN curl -sSfL https://github.com/HalFrgrd/flyline/releases/download/${FLYLINE_INSTALL_VERSION}/install.sh | FLYLINE_INSTALL_VERSION=${FLYLINE_INSTALL_VERSION} sh
88

99
RUN bash -i -c "flyline --version"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
FROM specific-bash-version
22

3-
ARG FLYLINE_RELEASE_VERSION
3+
ARG FLYLINE_INSTALL_VERSION
44

55
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
66

7-
RUN curl -sSfL https://raw.githubusercontent.com/HalFrgrd/flyline/master/install.sh | FLYLINE_RELEASE_VERSION=${FLYLINE_RELEASE_VERSION} sh
7+
RUN curl -sSfL https://github.com/HalFrgrd/flyline/releases/download/${FLYLINE_INSTALL_VERSION}/install.sh | FLYLINE_INSTALL_VERSION=${FLYLINE_INSTALL_VERSION} sh
88

99
RUN /bin/bash -i -c "flyline --version"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
FROM ubuntu:22.04
22

3-
ARG FLYLINE_RELEASE_VERSION
3+
ARG FLYLINE_INSTALL_VERSION
44

55
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
66

77

8-
RUN curl -sSfL https://raw.githubusercontent.com/HalFrgrd/flyline/master/install.sh | FLYLINE_RELEASE_VERSION=${FLYLINE_RELEASE_VERSION} sh
8+
RUN curl -sSfL https://github.com/HalFrgrd/flyline/releases/download/${FLYLINE_INSTALL_VERSION}/install.sh | FLYLINE_INSTALL_VERSION=${FLYLINE_INSTALL_VERSION} sh
99

1010
RUN /bin/bash -i -c "flyline --version"

install.sh

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
#!/bin/sh
22
# Flyline installer
3-
# Usage: curl -sSfL https://raw.githubusercontent.com/HalFrgrd/flyline/master/install.sh | sh
3+
# Usage: curl -sSfL https://github.com/HalFrgrd/flyline/releases/latest/download/install.sh | sh
44

55
set -eu
66

7+
expand_path() {
8+
case "$1" in
9+
'~/'*) echo "${HOME}/${1#~/}" ;;
10+
'~') echo "${HOME}" ;;
11+
*) echo "$1" ;;
12+
esac
13+
}
14+
715
REPO="HalFrgrd/flyline"
8-
INSTALL_DIR="${HOME}/.local/lib"
16+
if [ -n "${FLYLINE_INSTALL_DIR:-}" ]; then
17+
INSTALL_DIR="$(expand_path "$FLYLINE_INSTALL_DIR")"
18+
elif [ -n "${FLYLINE_LOAD_DIR:-}" ]; then
19+
INSTALL_DIR="$(expand_path "$FLYLINE_LOAD_DIR")"
20+
else
21+
INSTALL_DIR="${HOME}/.local/lib"
22+
fi
923
BASHRC="${HOME}/.bashrc"
1024

1125
# ---------------------------------------------------------------------------
@@ -193,9 +207,9 @@ main() {
193207

194208
say "Detected target: ${TARGET}"
195209

196-
if [ -n "${FLYLINE_RELEASE_VERSION:-}" ]; then
197-
say "Using specified release version: ${FLYLINE_RELEASE_VERSION}"
198-
VERSION="${FLYLINE_RELEASE_VERSION}"
210+
if [ -n "${FLYLINE_INSTALL_VERSION:-}" ]; then
211+
say "Using specified release version: ${FLYLINE_INSTALL_VERSION}"
212+
VERSION="${FLYLINE_INSTALL_VERSION}"
199213
else
200214
say "Fetching latest release information..."
201215
VERSION="$(get_latest_version)"
@@ -220,7 +234,8 @@ main() {
220234
# shellcheck disable=SC2064
221235
trap "rm -rf '$TMP_DIR'" EXIT
222236

223-
say "Downloading ${ARCHIVE} from ${DOWNLOAD_URL}..."
237+
say "Downloading ${ARCHIVE} from
238+
${DOWNLOAD_URL}..."
224239
download "$DOWNLOAD_URL" "${TMP_DIR}/${ARCHIVE}"
225240

226241
if [ -n "$SHA256_URL" ]; then
@@ -233,25 +248,6 @@ main() {
233248
|| err "Checksum verification failed for ${ARCHIVE}."
234249
fi
235250

236-
# Prompt for install directory; read from /dev/tty so it works when piped.
237-
# Falls back to the default when no terminal is available (e.g. CI).
238-
say "Enter install directory (leave blank to use: ~/.local/lib)"
239-
printf '> ' >&2
240-
input_dir=""
241-
if [ -t 0 ]; then
242-
read -r input_dir || true
243-
elif [ -r /dev/tty ]; then
244-
read -r input_dir </dev/tty || true
245-
fi
246-
if [ -n "$input_dir" ]; then
247-
# Expand a leading ~/ to $HOME/.
248-
# shellcheck disable=SC2088
249-
case "$input_dir" in
250-
'~/'*) input_dir="${HOME}/${input_dir#~/}" ;;
251-
'~') input_dir="${HOME}" ;;
252-
esac
253-
INSTALL_DIR="$input_dir"
254-
fi
255251

256252
mkdir -p "$INSTALL_DIR"
257253

@@ -276,14 +272,12 @@ main() {
276272
say "Installed: ${LIB_PATH}"
277273

278274
# Update or add 'enable -f ... flyline' in ~/.bashrc.
279-
ENABLE_CMD="enable -f ${LIB_PATH} flyline"
280-
if [ -f "$BASHRC" ] && grep -qE '^enable( -f [^ ]*)? flyline( |$)' "$BASHRC"; then
281-
new_content=$(sed -E "s|^enable( -f [^ ]*)? flyline( .*)?$|${ENABLE_CMD}|" "$BASHRC")
282-
printf '%s' "$new_content" > "$BASHRC"
283-
say "Updated flyline configuration in ${BASHRC}"
284-
else
275+
if [ -z "${FLYLINE_VERSION:-}" ]; then
276+
ENABLE_CMD="enable -f ${LIB_PATH} flyline"
285277
printf '\n# Flyline - enhanced Bash experience\n%s\n' "$ENABLE_CMD" >> "$BASHRC"
286278
say "Added flyline to ${BASHRC}"
279+
else
280+
say "Flyline is already installed (detected ${FLYLINE_VERSION}); skipping .bashrc modification."
287281
fi
288282

289283

@@ -307,11 +301,27 @@ main() {
307301
fi
308302

309303
say ""
310-
say "Installation complete!"
311-
say ' To activate in the current shell:'
312-
say " $ENABLE_CMD"
313-
say ' Or open a new terminal and run the tutorial:'
314-
say " flyline run-tutorial"
304+
if [ -n "${FLYLINE_VERSION:-}" ]; then
305+
say "Upgrade from ${FLYLINE_VERSION} -> ${VERSION}, run \`flyline changelog\` to see what's changed."
306+
say "To activate the upgrade, open a new shell."
307+
if [ -n "${FLYLINE_LOAD_DIR:-}" ]; then
308+
resolved_load_dir="$(expand_path "$FLYLINE_LOAD_DIR")"
309+
if [ "$resolved_load_dir" != "$INSTALL_DIR" ]; then
310+
warn "The upgrade installation directory ($INSTALL_DIR) is different from the currently running load directory ($resolved_load_dir)."
311+
warn "Please make sure to update your ~/.bashrc or other startup scripts to point to the new libflyline."
312+
fi
313+
fi
314+
else
315+
say "Installation complete!"
316+
say ' To activate in the current shell:'
317+
if [ -z "${FLYLINE_INSTALL_DIR:-}" ]; then
318+
say " $ENABLE_CMD"
319+
else
320+
say " enable -d flyline && enable -f ${LIB_PATH} flyline"
321+
fi
322+
say ' Or open a new terminal and run the tutorial:'
323+
say " flyline run-tutorial"
324+
fi
315325

316326
# Detect if ble.sh is running or configured in ~/.bashrc
317327
if [ -n "${_ble_version:-}" ] || { [ -f "$BASHRC" ] && grep -q 'ble\.sh' "$BASHRC"; }; then

src/active_suggestions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ impl ActiveSuggestionsBuilder {
12201220
self
12211221
}
12221222

1223+
#[allow(dead_code)]
12231224
pub fn with_should_run_flycomp(mut self, should_run_flycomp: bool) -> Self {
12241225
self.should_run_flycomp = should_run_flycomp;
12251226
self

src/app/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ impl<'a> App<'a> {
409409
fn new(settings: &'a mut Settings) -> Self {
410410
let unfinished_from_prev_command =
411411
unsafe { crate::bash_symbols::current_command_line_count } > 0;
412-
413-
let buffer = TextBuffer::new("");
412+
let initial_buf_val = settings.initial_buffer.take().unwrap_or_default();
413+
let buffer = TextBuffer::new(&initial_buf_val);
414414
let formatted_buffer_cache = FormattedBuffer::default();
415415

416416
bash_funcs::reset_caches();
@@ -423,7 +423,7 @@ impl<'a> App<'a> {
423423
});
424424
crate::threads::register_thread(crate::threads::ThreadTag::Warming, warming_handle);
425425

426-
App {
426+
let mut app = App {
427427
mode: AppRunningState::Running,
428428
buffer,
429429
formatted_buffer_cache,
@@ -470,7 +470,10 @@ impl<'a> App<'a> {
470470
right_click_popup_pos: None,
471471
right_click_copy_target: None,
472472
last_activity_time: std::time::Instant::now(),
473-
}
473+
};
474+
475+
app.on_possible_buffer_change();
476+
app
474477
}
475478

476479
/// Return a mutable reference to the history manager for the given fuzzy source.
@@ -1489,7 +1492,7 @@ impl<'a> App<'a> {
14891492
ContentMode::TabCompletion(_) | ContentMode::TabCompletionWaiting { .. }
14901493
);
14911494

1492-
if self.settings.auto_suggest || is_tab_completion_active {
1495+
if (self.settings.auto_suggest || is_tab_completion_active) && self.last_key.is_some() {
14931496
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14941497
enum CompletionAction {
14951498
Keep,

src/bash_funcs.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,7 @@ pub fn read_terminating_signal() -> c_int {
18341834
}
18351835

18361836
#[cfg(not(test))]
1837+
#[allow(dead_code)]
18371838
pub fn set_env_var(name: &str, value: &str) -> Result<()> {
18381839
unsafe {
18391840
let name_cstr = std::ffi::CString::new(name)?;
@@ -1850,13 +1851,38 @@ pub fn set_env_var(name: &str, value: &str) -> Result<()> {
18501851
}
18511852

18521853
#[cfg(test)]
1854+
#[allow(dead_code)]
18531855
pub fn set_env_var(name: &str, value: &str) -> Result<()> {
18541856
// SAFETY: Tests that mutate process env vars run inside `rusty_fork_test!`
18551857
// forked subprocesses, so the mutation cannot race with other threads.
18561858
unsafe { std::env::set_var(name, value) };
18571859
Ok(())
18581860
}
18591861

1862+
#[cfg(not(test))]
1863+
pub fn export_env_var(name: &str, value: &str) -> Result<()> {
1864+
unsafe {
1865+
let name_cstr = std::ffi::CString::new(name)?;
1866+
let value_cstr = std::ffi::CString::new(value)?;
1867+
let var = bash_symbols::bind_variable(name_cstr.as_ptr(), value_cstr.as_ptr(), 0);
1868+
if var.is_null() {
1869+
return Err(anyhow::anyhow!(
1870+
"Failed to export environment variable '{}'",
1871+
name
1872+
));
1873+
}
1874+
(*var).attributes |= 0x0000001; // att_exported
1875+
bash_symbols::array_needs_making = 1;
1876+
Ok(())
1877+
}
1878+
}
1879+
1880+
#[cfg(test)]
1881+
pub fn export_env_var(name: &str, value: &str) -> Result<()> {
1882+
unsafe { std::env::set_var(name, value) };
1883+
Ok(())
1884+
}
1885+
18601886
#[cfg(not(test))]
18611887
pub fn unset_env_var(name: &str) -> Result<()> {
18621888
unsafe {

0 commit comments

Comments
 (0)