mirror of
https://github.com/getcompanion-ai/computer-guest.git
synced 2026-04-15 03:00:42 +00:00
feat: update pure prompt zsh naming nad other guest os files (#6)
This commit is contained in:
parent
63b6a452b0
commit
ef8f354291
4 changed files with 63 additions and 5 deletions
|
|
@ -3,8 +3,25 @@ case $- in
|
|||
*) return ;;
|
||||
esac
|
||||
|
||||
computer_prompt_base_name() {
|
||||
local name=""
|
||||
if [ -n "${COMPUTER_NAME:-}" ]; then
|
||||
name="${COMPUTER_NAME}"
|
||||
elif [ -n "${COMPUTER_HANDLE:-}" ]; then
|
||||
name="${COMPUTER_HANDLE}"
|
||||
elif [ -r /etc/microagent/machine-name ]; then
|
||||
IFS= read -r name </etc/microagent/machine-name || true
|
||||
elif [ -r /etc/hostname ]; then
|
||||
IFS= read -r name </etc/hostname || true
|
||||
fi
|
||||
if [ -z "$name" ]; then
|
||||
name="microagentcomputer"
|
||||
fi
|
||||
printf '%s' "$name"
|
||||
}
|
||||
|
||||
computer_prompt_name() {
|
||||
printf '%s' "${COMPUTER_NAME:-${COMPUTER_HANDLE:-microagentcomputer}}"
|
||||
printf '%s(computer)' "$(computer_prompt_base_name)"
|
||||
}
|
||||
|
||||
export EDITOR="${EDITOR:-nvim}"
|
||||
|
|
|
|||
|
|
@ -12,8 +12,25 @@ setopt prompt_subst
|
|||
bindkey -v
|
||||
bindkey '^?' backward-delete-char
|
||||
|
||||
computer_prompt_base_name() {
|
||||
local name=""
|
||||
if [ -n "${COMPUTER_NAME:-}" ]; then
|
||||
name="${COMPUTER_NAME}"
|
||||
elif [ -n "${COMPUTER_HANDLE:-}" ]; then
|
||||
name="${COMPUTER_HANDLE}"
|
||||
elif [ -r /etc/microagent/machine-name ]; then
|
||||
IFS= read -r name </etc/microagent/machine-name || true
|
||||
elif [ -r /etc/hostname ]; then
|
||||
IFS= read -r name </etc/hostname || true
|
||||
fi
|
||||
if [ -z "$name" ]; then
|
||||
name="microagentcomputer"
|
||||
fi
|
||||
printf '%s' "$name"
|
||||
}
|
||||
|
||||
computer_prompt_name() {
|
||||
printf '%s' "${COMPUTER_NAME:-${COMPUTER_HANDLE:-microagentcomputer}}"
|
||||
printf '%s(computer)' "$(computer_prompt_base_name)"
|
||||
}
|
||||
|
||||
ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/zsh"
|
||||
|
|
@ -50,6 +67,7 @@ if [ -r /opt/zsh/pure/pure.zsh ] && [ -r /opt/zsh/pure/async.zsh ]; then
|
|||
autoload -Uz promptinit
|
||||
promptinit
|
||||
if prompt pure >/dev/null 2>&1; then
|
||||
prompt_pure_context() { :; }
|
||||
zstyle ':prompt:pure:path' color blue
|
||||
pure_prompt="$PROMPT"
|
||||
PROMPT='%F{green}$(computer_prompt_name)%f '"$pure_prompt"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,18 @@ log() {
|
|||
printf '[microagent-init] %s\n' "$*" >&2
|
||||
}
|
||||
|
||||
read_machine_name() {
|
||||
if [ -r /etc/microagent/machine-name ]; then
|
||||
tr -d '\r\n' </etc/microagent/machine-name
|
||||
return 0
|
||||
fi
|
||||
if [ -r /etc/hostname ]; then
|
||||
tr -d '\r\n' </etc/hostname
|
||||
return 0
|
||||
fi
|
||||
printf 'microagentcomputer'
|
||||
}
|
||||
|
||||
mountpoint -q /proc || mount -t proc proc /proc
|
||||
mountpoint -q /sys || mount -t sysfs sysfs /sys
|
||||
mountpoint -q /dev || mount -t devtmpfs devtmpfs /dev
|
||||
|
|
@ -61,6 +73,18 @@ if ! /usr/local/bin/microagent-network-up >/var/log/network.log 2>&1; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
machine_name="$(read_machine_name)"
|
||||
export COMPUTER_NAME="$machine_name"
|
||||
printf '%s\n' "$machine_name" >/etc/hostname
|
||||
cat >/etc/hosts <<EOF
|
||||
127.0.0.1 localhost
|
||||
127.0.1.1 $machine_name
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
EOF
|
||||
hostname "$machine_name" >/dev/null 2>&1 || true
|
||||
|
||||
if [ ! -f /etc/ssh/ssh_host_ed25519_key ]; then
|
||||
log "generating ssh host keys"
|
||||
ssh-keygen -A
|
||||
|
|
|
|||
|
|
@ -40,9 +40,8 @@ ip link set dev "$primary_iface" up
|
|||
ip addr replace "${guest_ip}/30" dev "$primary_iface"
|
||||
ip route replace default via "$gateway_ip" dev "$primary_iface"
|
||||
|
||||
if [ -w /etc/resolv.conf ]; then
|
||||
mkdir -p /etc
|
||||
cat >/etc/resolv.conf <<'EOF'
|
||||
nameserver 1.1.1.1
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue