Skip to content

Commit 4269a8c

Browse files
committed
Script to install the files_for_home
Add a script and some documentation for it which allows users to install the .bashrc and .profile in the files_for_home folder automatically.
1 parent 97bc2a1 commit 4269a8c

File tree

6 files changed

+108
-25
lines changed

6 files changed

+108
-25
lines changed

README

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ before you can do the Project Gutenberg-related exercises.
1616
Run the script in the resources/gutenberg/ directory, i.e.
1717
cd resources/gutenberg/
1818
./download.sh
19+
20+
If you want a more fancy .bashrc configuration, e.g. a coloured
21+
output of grep or a colored command prompt, run the install.sh
22+
script from the files_for_home directory.
23+
cd files_for_home
24+
./install.sh
25+
26+
Note that this will replace your current .bashrc and your
27+
current .profile in case these files exist.

files_for_home/.bashrc

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# ~/.bashrc: executed by bash(1) for non-login shells.
22

3+
###################################
4+
# Settings for this .bashrc
5+
6+
# change the following to 1 if the return code shall show up.
7+
SHOW_RETURN_CODE=0
8+
9+
###################################
10+
311
is_interactive_shell() {
412
case $- in
513
*i*) return 0;;
@@ -10,6 +18,10 @@ is_interactive_shell() {
1018
# If not running interactively, don't do anything
1119
is_interactive_shell || return 0
1220

21+
###################################
22+
# history settings:
23+
24+
1325
# Ignore duplicate lines and space lines:
1426
export HISTCONTROL=ignoreboth
1527

@@ -19,10 +31,48 @@ shopt -s histappend
1931
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
2032
export HISTSIZE=2000
2133

34+
###################################
35+
# other shell options:
36+
2237
# check the window size after each command and, if necessary,
2338
# update the values of LINES and COLUMNS.
2439
shopt -s checkwinsize
2540

41+
# Set vi editing mode:
42+
set -o vi
43+
44+
###################################
45+
# colour for the shell
46+
47+
# Use color if terminal has the capability
48+
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
49+
# We have color support; assume it's compliant with Ecma-48
50+
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
51+
# a case would tend to support setf rather than setaf.)
52+
53+
UCOL="\[\033[0;00m\]" # color for user
54+
HCOL="\[\033[0;33m\]" # color for host
55+
PCOL="\[\033[1;34m\]" # color for dir
56+
DEFC="\[\033[0;00m\]" # default color
57+
PS1="${debian_chroot:+($debian_chroot)}$UCOL\u$DEFC@$HCOL\h$DEFC:$PCOL\w$DEFC\$ "
58+
59+
unset UCOL HCOL PCOL DEFC
60+
else
61+
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
62+
fi
63+
64+
# If this is an xterm set the title to user@host:dir
65+
case "$TERM" in
66+
xterm*|rxvt*)
67+
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
68+
;;
69+
*)
70+
;;
71+
esac
72+
73+
###################################
74+
# colour for other programs:
75+
2676
# Enable color support of ls
2777
if [ -x /usr/bin/dircolors ]; then
2878
eval "`dircolors -b`"
@@ -40,13 +90,27 @@ export LS_OPTIONS='--color=auto'
4090
alias ls='ls -vF $LS_OPTIONS'
4191
alias ll='ls -al'
4292

43-
alias cd..='cd ..'
44-
alias ..='cd ..'
93+
unset GREP_OPTIONS
4594

95+
###################################
96+
# misc
97+
98+
# change the prompt if the user wishes
99+
if [ "$BASH" == "/bin/bash" -a "$SHOW_RETURN_CODE" == "1" ]; then
100+
promt_extra() {
101+
local RET=$?
102+
if [ "$RET" != "0" ]; then
103+
echo -e "rc: \033[0;32m$RET\033[0;00m"
104+
fi
105+
}
106+
export PROMPT_COMMAND='promt_extra'
107+
fi
108+
109+
# Enable bash completion:
46110
if [ -f /etc/bash_completion ]; then
47111
. /etc/bash_completion
48112
fi
49113

50-
if [ -f "$HOME/return_code_prompt" ]; then
51-
. "$HOME/return_code_prompt"
52-
fi
114+
###################################
115+
# cleanup
116+
unset SHOW_RETURN_CODE

files_for_home/.profile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# if running bash
2+
if [ -n "$BASH_VERSION" ]; then
3+
# include .bashrc if it exists
4+
if [ -f "$HOME/.bashrc" ]; then
5+
. "$HOME/.bashrc"
6+
fi
7+
fi

files_for_home/README

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
These files are recommended settings for the course.
2-
You should copy them to your home directory using
2+
You should copy them to your home directory by running
3+
./install.sh
34

4-
cp .bashrc ~
5-
6-
-------------------------------------------------------
7-
8-
If you want return codes to show up in your terminal,
9-
also copy the file
10-
cp return_code_prompt ~
5+
in case you created a .bashrc or .profile file, they
6+
will be moved to .bashrc.old and .profile.old

files_for_home/install.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# install new files
4+
for file in .bashrc .profile; do
5+
if [ ! -f "$file" ]; then
6+
echo "Please run script directly from the directory using ./$(basename "$0")." >&2
7+
exit 1
8+
fi
9+
10+
# the target file:
11+
TFILE="$HOME/$file"
12+
13+
# if target file exists move it to .old:
14+
[ -f "$TFILE" ] && mv "$TFILE" "$TFILE.old"
15+
16+
# copy new file:
17+
cp "$file" "$TFILE"
18+
done
19+

files_for_home/return_code_prompt

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)