Last active
March 10, 2025 17:44
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Termux:
pkg install nano opensshnano $PREFIX/bin/http_file_servechmod +x $PREFIX/bin/http_file_serve