Skip to content

Instantly share code, notes, and snippets.

@unique-EJ
Last active March 10, 2025 17:44
Show Gist options
  • Select an option

  • Save unique-EJ/64b2f43dfb5489a52a020114b374ffdc to your computer and use it in GitHub Desktop.

Select an option

Save unique-EJ/64b2f43dfb5489a52a020114b374ffdc to your computer and use it in GitHub Desktop.
Bash edit file, local file server commands (command interpreter shell initialization snippets).
#!/usr/bin/env bash
# Download: raw file is in https://gist.github.com/unique-EJ/64b2f43dfb5489a52a020114b374ffdc
# curl can download the URL.
# Usage: no options, puts command snippets into the Bash initialization file.
declare edit_file="$(cat <<"EOF"
# Edit a file. Line numbers - Meta key (Alt, Cmd, or Esc), N.
function edit_file () {
[[ ! -f "$1" || ! -w "$1" ]] && return 1;
nano --cutfromcursor --autoindent --smarthome -- $1;
}
EOF
)";
declare file_share="$(cat <<"EOF"
#!/usr/bin/env bash
# Simple local file server, Python, to serve current directory.
# Command name search.
declare python="$( command -p -v python; )"
if [[ ! -x "$python" ]]; then
declare python="$( command -p -v python3; )";
declare -i python_version=3;
else
declare python_version_string="$( $python -V; )";
declare -i python_version=${python_version_string:7:1};
fi
if (( ${python_version} < 3 )); then
declare service="python -m SimpleHTTPServer 2080";
else
declare service="python3 -m http.server 2080 --bind $( hostname -I; )";
fi
eval "${service}" "$(test "$1" = "--quiet" && env echo "&>> /dev/null")" ";";
EOF
)";
env echo -n "${edit_file}" >> ~/.bashrc;
env echo -n "env cat - > /usr/bin/http_file_serve <<\"EOF\"
${file_share}
EOF
" | sudo -E -s;
sudo chmod +x /usr/bin/http_file_serve;
@unique-EJ
Copy link
Author

unique-EJ commented Mar 10, 2025

Termux:

  1. pkg install nano openssh
  2. nano $PREFIX/bin/http_file_serve
  3. Put lines 16 - 33 in.
  4. chmod +x $PREFIX/bin/http_file_serve
  5. Local port forward 127.0.0.1 port 2080 from Termux on a device with SSH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment