Ticket #10687: 0001-setarch-profile-Contain-the-current-arch-in-PS1.-Pro.patch

File 0001-setarch-profile-Contain-the-current-arch-in-PS1.-Pro.patch, 2.5 KB (added by puckipedia, 6 years ago)

The patch!

  • data/etc/profile

    From 34be1ef33c50193c4a9b7a0f751a10e13594dd33 Mon Sep 17 00:00:00 2001
    From: Puck Meerburg <puck@puckipedia.nl>
    Date: Mon, 17 Mar 2014 18:56:59 +0000
    Subject: [PATCH] setarch, profile: Contain the current arch in PS1. Probably
     avoids confusion
    
    ---
     data/etc/profile    |  8 +++++++-
     src/bin/setarch.cpp | 26 +++++++++++++++++++++++++-
     2 files changed, 32 insertions(+), 2 deletions(-)
    
    diff --git a/data/etc/profile b/data/etc/profile
    index 9765028..1284a88 100644
    a b if [ -z $BE_HOST_CPU ]; then  
    1212    . /boot/system/boot/SetupEnvironment
    1313fi
    1414
    15 export PS1="\w> "
     15# Set the PS1 to contain the current arch if `getarch' exists
     16if command -v getarch 2>- 1>-; then
     17    export PS1="[`getarch`] \w> "
     18else
     19    export PS1="[unknown] \w> "
     20fi
     21
    1622export HISTFILESIZE=50
    1723export HISTCONTROL=ignoredups
    1824
  • src/bin/setarch.cpp

    diff --git a/src/bin/setarch.cpp b/src/bin/setarch.cpp
    index b6fc26c..9abc9ae 100644
    a b static const char* kUsage =  
    3232    "Options:\n"
    3333    "  -h, --help\n"
    3434    "    Print this usage info.\n"
     35    "  -n, --no-ps1\n"
     36    "    Don't add the new architecture to PS1.\n"
    3537    "  -p, --print-path\n"
    3638    "    Only print the modified PATH variable value; don't execute any\n"
    3739    "    command.\n"
    int  
    136138main(int argc, const char* const* argv)
    137139{
    138140    bool printPath = false;
     141    bool noPS1Set = false;
    139142
    140143    while (true) {
    141144        static struct option sLongOptions[] = {
    142145            { "help", no_argument, 0, 'h' },
    143146            { "print-path", no_argument, 0, 'p' },
     147            { "no-ps1", no_argument, 0, 'n' },
    144148            { 0, 0, 0, 0 }
    145149        };
    146150
    147151        opterr = 0; // don't print errors
    148         int c = getopt_long(argc, (char**)argv, "+hp",
     152        int c = getopt_long(argc, (char**)argv, "+hpn",
    149153            sLongOptions, NULL);
    150154        if (c == -1)
    151155            break;
    main(int argc, const char* const* argv)  
    159163                printPath = true;
    160164                break;
    161165
     166            case 'n':
     167                noPS1Set = true;
     168                break;
     169
    162170            default:
    163171                print_usage_and_exit(true);
    164172                break;
    main(int argc, const char* const* argv)  
    211219        exit(1);
    212220    }
    213221
     222    // add current architecture to PS1
     223    if (!noPS1Set) {
     224        BString ps1(getenv("PS1"));
     225        BString arch_str;
     226        arch_str << "[" << architecture << "] ";
     227        ps1.Prepend(arch_str);
     228
     229        // set PS1
     230        if (setenv("PS1", ps1, 1) != 0) {
     231            fprintf(stderr, "Error: Failed to set PS1: %s\n", strerror(errno));
     232            exit(1);
     233        }
     234    }
     235
     236
     237
    214238    // if no command is given, get the user's shell
    215239    const char* shellCommand[2];
    216240    if (commandArgs == NULL) {