From da9d85783c63b24380c0090d07b0b47b1d941a04 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 11 Aug 2015 20:38:18 -0400 Subject: [PATCH] termux-tools: Improve the chsh command --- packages/termux-tools/build.sh | 2 +- packages/termux-tools/chsh | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/termux-tools/build.sh b/packages/termux-tools/build.sh index d4616217e..58387d8ee 100644 --- a/packages/termux-tools/build.sh +++ b/packages/termux-tools/build.sh @@ -1,6 +1,6 @@ TERMUX_PKG_HOMEPAGE=http://termux.com/ TERMUX_PKG_DESCRIPTION="Some tools for Termux" -TERMUX_PKG_VERSION=0.7 +TERMUX_PKG_VERSION=0.10 termux_step_make_install () { $CXX $CFLAGS $LDFLAGS -std=c++14 -Wall -Wextra -pedantic -Werror $TERMUX_PKG_BUILDER_DIR/*.cpp -o $TERMUX_PREFIX/bin/termux-elf-cleaner diff --git a/packages/termux-tools/chsh b/packages/termux-tools/chsh index 4fd785262..edc7abf31 100755 --- a/packages/termux-tools/chsh +++ b/packages/termux-tools/chsh @@ -1,22 +1,19 @@ -#!/system/bin/sh +#!/bin/sh set -e -u -SCRIPTNAME=$0 show_usage () { - echo "usage: $SCRIPTNAME [-s shell]" + echo "usage: chsh [-s shell]" echo "Change the login shell." } set_shell () { mkdir -p $HOME/.termux - NEW_SHELL=$1 - if test -x $PREFIX/bin/$NEW_SHELL; then - ln -f -s $PREFIX/bin/$NEW_SHELL $HOME/.termux/shell - elif test -x $NEW_SHELL; then + NEW_SHELL=$PREFIX/bin/$1 + if test -x $NEW_SHELL -a ! -d $NEW_SHELL; then ln -f -s $NEW_SHELL $HOME/.termux/shell else - echo "Error: $NEW_SHELL is not an executable file" + echo "$NEW_SHELL is not an executable file!" fi } @@ -31,5 +28,13 @@ while true; do esac done -echo "Error: Specify shell with the -s flag" -exit 1 +DEFAULT_SHELL=bash +if [ ! -x $PREFIX/bin/$DEFAULT_SHELL ]; then DEFAULT_SHELL=ash; fi + +echo Changing the login shell +echo Enter the new value, or press ENTER for the default +printf " Login Shell [$DEFAULT_SHELL]: " +read shell + +if [ -z "$shell" ]; then shell=$DEFAULT_SHELL; fi +set_shell $shell