Advertisement
v1ral_ITS

more of my great notes

Oct 25th, 2019
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.73 KB | None | 0 0
  1.  
  2. Sat Aug 18 13:35:19 EDT 2018
  3. NOTE:
  4. #################################################################################
  5. #
  6. # * Colors
  7. #
  8. # For improved display
  9. #
  10. #################################################################################
  11. #
  12.  
  13. # Normal color names
  14. CYAN="$(printf '\033[0;36m')"
  15. BLUE="$(printf '\033[0;34m')"
  16. BROWN="$(printf '\033[0;33m')"
  17. DARKGRAY="$(printf '\033[0;30m')"
  18. GRAY="$(printf '\033[0;37m')"
  19. GREEN="$(printf '\033[1;32m')"
  20. LIGHTBLUE="$(printf '\033[0;94m')"
  21. MAGENTA="$(printf '\033[1;35m')"
  22. PURPLE="$(printf '\033[0;35m')"
  23. RED="$(printf '\033[1;31m')"
  24. YELLOW="$(printf '\033[1;33m')"
  25. WHITE="$(printf '\033[1;37m')"
  26.  
  27. # Markup
  28. BOLD="${WHITE}"
  29.  
  30. # With background
  31. BG_BLUE="$(printf '\033[0;44m')"
  32.  
  33. # Semantic names
  34. HEADER="${WHITE}"
  35. NORMAL="$(printf '\033[0m')"
  36. WARNING="${RED}"
  37. SECTION="${YELLOW}"
  38. NOTICE="${YELLOW}"
  39. OK="${GREEN}"
  40. BAD="${RED}"
  41.  
  42. #
  43. #################################################################################
  44. #
  45.  
  46. #================================================================================
  47.  
  48.  
  49. # So that this file can also be read with `.' or `source' ...
  50. compaudit() { # Define and then call
  51.  
  52. # Audit the fpath to assure that it contains all the directories needed by
  53. # the completion system, and that those directories are at least unlikely
  54. # to contain dangerous files. This is far from perfect, as the modes or
  55. # ownership of files or directories might change between the time of the
  56. # audit and the time the function is executed.
  57.  
  58. # This function is designed to be called from compinit, which assumes that
  59. # it is in the same directory, i.e., it can be autoloaded from the initial
  60. # fpath as compinit was. Most local parameter names in this function must
  61. # therefore be the same as those used in compinit.
  62.  
  63. emulate -L zsh
  64. setopt extendedglob
  65.  
  66. [[ -n $commands[getent] ]] || getent() {
  67. if [[ $1 = hosts ]]; then
  68. sed 's/#.*//' /etc/$1 | grep -w $2
  69. elif [[ $2 = <-> ]]; then
  70. grep ":$2:[^:]*$" /etc/$1
  71. else
  72. grep "^$2:" /etc/$1
  73. fi
  74. }
  75.  
  76. # The positional parameters are the directories to check, else fpath.
  77. if (( $# )); then
  78. local _compdir=''
  79. elif (( $#fpath == 0 )); then
  80. print 'compaudit: No directories in $fpath, cannot continue' 1>&2
  81. return 1
  82. else
  83. set -- $fpath
  84. fi
  85.  
  86. # _i_check is defined by compinit; used here as a test for whether this
  87. # function is running standalone or was called by compinit. If called
  88. # by compinit, we use parameters that are defined in compinit's scope,
  89. # otherwise we make them local here.
  90. (( $+_i_check )) || {
  91. local _i_q _i_line _i_file _i_fail=verbose
  92. local -a _i_files _i_addfiles _i_wdirs _i_wfiles
  93. local -a -U +h fpath
  94. }
  95.  
  96. fpath=( $* )
  97.  
  98. # _compdir may be defined by the user; see the compinit documentation.
  99. # If it isn't defined, we want it to point somewhere sensible, but the
  100. # user is allowed to set it to empty to bypass the check below.
  101. (( $+_compdir )) || {
  102. local _compdir=${fpath[(r)*/$ZSH_VERSION/*]}
  103. [[ -z $_compdir ]] && _compdir=$fpath[1]
  104. ### [[ -d $_compdir/../Base ]] && _compdir=${_compdir:h}
  105. }
  106.  
  107. _i_wdirs=()
  108. _i_wfiles=()
  109.  
  110. _i_files=( ${^~fpath:/.}/^([^_]*|*~|*.zwc)(N) )
  111. if [[ -n $_compdir ]]; then
  112. if [[ $#_i_files -lt 20 || $_compdir = */Base || -d $_compdir/Base ]]; then
  113. # Too few files: we need some more directories, or we need to check
  114. # that all directories (not just Base) are present.
  115. _i_addfiles=()
  116. if [[ -d $_compdir/Base/Core ]]; then
  117. # Add all the Completion subdirectories (CVS-layout)
  118. _i_addfiles=(${_compdir}/*/*(/^M))
  119. elif [[ -d $_compdir/Base ]]; then
  120. # Likewise (installation-layout)
  121. _i_addfiles=(${_compdir}/*(/^M))
  122. fi
  123. for _i_line in {1..$#_i_addfiles}; do
  124. (( $_i_line )) || break
  125. _i_file=${_i_addfiles[$_i_line]}
  126. [[ -d $_i_file && -z ${fpath[(r)$_i_file]} ]] ||
  127. _i_addfiles[$_i_line]=
  128. done
  129. fpath=($fpath $_i_addfiles)
  130. _i_files=( ${^~fpath:/.}/^([^_]*|*~|*.zwc)(N) )
  131. fi
  132. fi
  133.  
  134. [[ $_i_fail == use ]] && return 0
  135.  
  136. # We will always allow files to be owned by root and the owner of the
  137. # present process.
  138. local _i_owners="u0u${EUID}"
  139.  
  140. # Places we will look for a link to the executable
  141. local -a _i_exes
  142. _i_exes=(
  143. /proc/$$/exe
  144. /proc/$$/object/a.out
  145. )
  146. local _i_exe
  147.  
  148. # If we can find out who owns the executable, we will allow files to
  149. # be owned by that user, too. The argument is that if you don't trust
  150. # the owner of the executable, it's way too late to worry about it now...
  151. for _i_exe in $_i_exes; do
  152. if [[ -e $_i_exe ]] ;then
  153. if zmodload -F zsh/stat b:zstat 2>/dev/null; then
  154. local -A _i_stathash
  155. if zstat -H _i_stathash $_i_exe &&
  156. [[ $_i_stathash[uid] -ne 0 ]]; then
  157. _i_owners+="u${_i_stathash[uid]}"
  158. fi
  159. fi
  160. break
  161. fi
  162. done
  163.  
  164. # We search for:
  165. # - world/group-writable directories in fpath not owned by $_i_owners
  166. # - parent-directories of directories in fpath that are world/group-writable
  167. # and not owned by $_i_owners (that would allow someone to put a
  168. # digest file for one of the directories into the parent directory)
  169. # - digest files for one of the directories in fpath not owned by $_i_owners
  170. # - and for files in directories from fpath not owned by $_i_owners
  171. # (including zwc files)
  172.  
  173. _i_wdirs=( ${^fpath}(N-f:g+w:,-f:o+w:,-^${_i_owners})
  174. ${^fpath:h}(N-f:g+w:,-f:o+w:,-^${_i_owners}) )
  175.  
  176. # RedHat Linux "per-user groups" check. This is tricky, because it's very
  177. # difficult to tell whether the sysadmin has put someone else into your
  178. # "private" group (e.g., via the default group field in /etc/passwd, or
  179. # by NFS group sharing with an untrustworthy machine). So we must assume
  180. # that this has not happened, and pick the best group.
  181.  
  182. if (( $#_i_wdirs )); then
  183. local GROUP GROUPMEM _i_pw _i_gid
  184. if ((UID == EUID )); then
  185. getent group $LOGNAME | IFS=: read GROUP _i_pw _i_gid GROUPMEM
  186. else
  187. getent group $EGID | IFS=: read GROUP _i_pw _i_gid GROUPMEM
  188. fi
  189.  
  190. if [[ $GROUP == $LOGNAME && ( -z $GROUPMEM || $GROUPMEM == $LOGNAME ) ]]
  191. then
  192. _i_wdirs=( ${^_i_wdirs}(N-f:g+w:^g:${GROUP}:,-f:o+w:,-^${_i_owners}) )
  193. fi
  194. fi
  195.  
  196. if [[ -f /etc/debian_version ]]
  197. then
  198. local _i_ulwdirs
  199. _i_ulwdirs=( ${(M)_i_wdirs:#/usr/local/*} )
  200. _i_wdirs=( ${_i_wdirs:#/usr/local/*} ${^_i_ulwdirs}(Nf:g+ws:^g:staff:,f:o+w:,^u0) )
  201. fi
  202.  
  203. _i_wdirs=( $_i_wdirs ${^fpath}.zwc^([^_]*|*~)(N-^${_i_owners}) )
  204. _i_wfiles=( ${^fpath}/^([^_]*|*~)(N-^${_i_owners}) )
  205.  
  206. case "${#_i_wdirs}:${#_i_wfiles}" in
  207. (0:0) _i_q= ;;
  208. (0:*) _i_q=files ;;
  209. (*:0) _i_q=directories ;;
  210. (*:*) _i_q='directories and files' ;;
  211. esac
  212.  
  213. if [[ -n "$_i_q" ]]; then
  214. [[ $_i_fail == verbose ]] && {
  215. print There are insecure ${_i_q}: 1>&2
  216. print -l - $_i_wdirs $_i_wfiles
  217. }
  218. return 1
  219. fi
  220. return 0
  221.  
  222. } # Define and then call
  223.  
  224. compaudit "$@"
  225.  
  226.  
  227.  
  228.  
  229. ---------------------------------------------
  230.  
  231.  
  232. HOSTARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
  233. -e s/sun4u/sparc/ -e s/sparc64/sparc/ \
  234. -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \
  235. -e s/s390x/s390/ -e s/parisc64/parisc/ \
  236. -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
  237. -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
  238. -e s/tile.*/tile/ )
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246. -----------------------------------------------------
  247.  
  248.  
  249.  
  250.  
  251.  
  252. /usr/src/linux-headers-4.15.0-29/tools && \
  253. make
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272. ___________________________________________________________
  273.  
  274.  
  275. sins zpaq ziptime zipmerge zipcmp zescrow-client++ xarchiver wimtools wit whohas wget2-dev wget2 axel aria2 vfu unalz ubuntukylin-keyring ubuntu-kylin-software-center ubumirror trydiffoscope tig tardy tar-split
  276.  
  277. ---------------------------
  278.  
  279.  
  280.  
  281. #!/bin/bash
  282. FILES="$PWD/*"
  283. zenity --title "List" --width=660 --height=350 --text "Test" --list --column "Current Directory" --add-entry $FILES --column "Choice" --checklist
  284.  
  285.  
  286. -------------------------------------
  287.  
  288.  
  289. ######################
  290. # START # v1ral_ITS #
  291. ######################
  292.  
  293. A bash wrapper script that prompts for the format, which includes all available renditions, including audio-only, video-only.
  294.  
  295. Accepts both absolute youtube URLs and video IDs.
  296.  
  297. ############################################################################################################################
  298.  
  299. #!/usr/bin/env bash
  300. # Download youtube video with desired quality
  301.  
  302. # youtube-dl accepts both fully qualified URLs and video id's such as AQcQgfvfF1M
  303.  
  304. url="$*"
  305.  
  306. echo "Fetching available formats for $url..."
  307. youtube-dl -F "$url"
  308. read -p "Please enter the desired quality code: " FORMAT
  309.  
  310. echo "Streaming with quality $FORMAT..."
  311. mpv --cache=1024 $(youtube-dl -f $FORMAT -g "$url")
  312.  
  313.  
  314.  
  315.  
  316.  
  317. -----------------------------------------------------------------------------------------------------
  318.  
  319.  
  320.  
  321.  
  322. -----info
  323. Ubuntu-Studio 18.04 LTS "Bionic Beaver" - Release amd64 (20180426)
  324.  
  325.  
  326.  
  327. ------release_notes_url
  328. http://www.ubuntu.com/getubuntu/releasenotes?os=ubuntustudio&ver=18.04&lang=${LANG}
  329.  
  330.  
  331.  
  332. ---------casper-uuid-lowlatency
  333. 211e8078-e3d0-4165-8d61-9c75cbf4f9e4
  334.  
  335.  
  336.  
  337.  
  338. --------cd_type
  339. dvd/single
  340.  
  341. Sat Aug 18 21:05:29 EDT 2018
  342. NOTE:
  343.  
  344. ---------------------------------------------
  345.  
  346. anjuta docbook-defguide docbook-dsssl psgml gimp-help-en | gimp-help gimp-data-extras dblatex xfce4-panel faad mp3gain python-jppy
  347. libcairo2-doc libgraphite2-utils libgtk2.0-doc icu-doc libid3-tools libgnomeui-0 libgamin0 libnunit-doc monodoc-nunit-manual libpango1.0-doc
  348. libxext-doc monodoc-gtk-manual monodoc-gecko-manual python-funcsigs-doc pyliblo-utils python-liblo-docs python-mock-doc
  349. Recommended packages:
  350. kde-style-qtcurve-qt5 libgluezilla
  351.  
  352.  
  353. ____________________________________________________
  354. #!/bin/sh
  355.  
  356. ARG1=$1
  357. Ubuntu_Distrib="precise trusty utopic vivid" # + add new distrib here above
  358. # added the new distrib => l108
  359. Architecture="i386 amd64"
  360. CD_key="41317877"
  361. ## LUCID => no LPIA
  362. debug_mv="cp" # move files (mv) or just copy them (cp)
  363.  
  364.  
  365. ## functions ##
  366.  
  367. directories() {
  368. if test -d dists; then
  369. read -p "Remove 'dists' dir? (o/N)" RmDists
  370. if test "$RmDists" = "o" -o "$RmDists" = "O"; then
  371. rm -r dists
  372. fi
  373. fi
  374. mkdir dists
  375. for distrib in $Ubuntu_Distrib
  376. do
  377. MainDir=dists/$distrib
  378. mkdir $MainDir
  379. PoolDir=$MainDir/pool
  380. mkdir $PoolDir
  381. mkdir $PoolDir/all
  382. mkdir $PoolDir/all/cairo-dock
  383. mkdir $PoolDir/all/cairo-dock-plug-ins
  384. for archi in $Architecture
  385. do
  386. mkdir $PoolDir/$archi
  387. mkdir $PoolDir/$archi/cairo-dock
  388. mkdir $PoolDir/$archi/cairo-dock-plug-ins
  389. done
  390. done
  391. }
  392.  
  393. packages() {
  394. if ! test -d Incoming; then
  395. echo "You need to respect this tree:
  396. |-Incoming
  397. |-----|-cairo-dock
  398. |-----|-cairo-dock-plug-ins"
  399. read -p "Create these dirs (O) / Continue (c) / Stop (s) ?" packages_next
  400. if test "$packages_next" = "c" -o "$packages_next" = "C"; then
  401. packages_questions
  402. elif test "$packages_next" = "s" -o "$packages_next" = "S"; then
  403. echo "Stop"
  404. exit 0
  405. else
  406. mkdir -p Incoming/cairo-dock
  407. mkdir Incoming/cairo-dock-plug-ins
  408. echo "\tYou need to move deb packages in it and relaunch the script"
  409. exit 0
  410. fi
  411. fi
  412.  
  413. if test -d dists; then
  414. read -p "Remove 'dists' dir? (o/n)" RmDists
  415. if test "$RmDists" = "n" -o "$RmDists" = "N"; then
  416. echo "Stop"
  417. exit 0
  418. fi
  419. rm -r dists
  420. fi
  421. directories
  422.  
  423. echo "Move packages:"
  424. for distrib in $Ubuntu_Distrib
  425. do
  426. MainDir=dists/$distrib
  427. PoolDir=$MainDir/pool
  428. echo "\n\t$distrib"
  429. # all
  430. $debug_mv Incoming/cairo-dock/*~"$distrib"_all.deb $PoolDir/all/cairo-dock
  431. $debug_mv Incoming/cairo-dock-plug-ins/*~"$distrib"_all.deb $PoolDir/all/cairo-dock-plug-ins
  432. for archi in $Architecture
  433. do
  434. $debug_mv Incoming/cairo-dock/*~"$distrib"_$archi.deb $PoolDir/$archi/cairo-dock
  435. $debug_mv Incoming/cairo-dock-plug-ins/*~"$distrib"_$archi.deb $PoolDir/$archi/cairo-dock-plug-ins
  436. done
  437. done
  438. }
  439.  
  440. repository() {
  441. echo "Creating release and Packages files"
  442. for distrib in $Ubuntu_Distrib
  443. do
  444. echo "\tUbuntu $distrib"
  445. MainDir=dists/$distrib
  446. PoolDir=$MainDir/pool
  447. Version_distrib="unstable"
  448. Description_distrib="Ubuntu Unstable"
  449. case $distrib in
  450. vivid)
  451. Version_distrib="15.04"
  452. Description_distrib="Ubuntu Vivid 15.04"
  453. ;;
  454. utopic)
  455. Version_distrib="14.10"
  456. Description_distrib="Ubuntu Utopic 14.10"
  457. ;;
  458. trusty)
  459. Version_distrib="14.04"
  460. Description_distrib="Ubuntu Trusty 14.04"
  461. ;;
  462. precise)
  463. Version_distrib="12.04"
  464. Description_distrib="Ubuntu Precise 12.04"
  465. ;;
  466. esac
  467. mkdir $MainDir/cairo-dock/
  468.  
  469. for archi in $Architecture
  470. do
  471. echo "\t\tArchitecture : $archi"
  472. Dir=$MainDir/cairo-dock/binary-$archi
  473. mkdir $Dir
  474.  
  475. # create index for each distribution and architecture
  476. echo "\t\t\tPackages - $archi"
  477. apt-ftparchive packages $PoolDir/all > $Dir/Packages
  478. apt-ftparchive packages $PoolDir/$archi >> $Dir/Packages
  479. cat $Dir/Packages | gzip -9c > $Dir/Packages.gz
  480. cat $Dir/Packages | bzip2 > $Dir/Packages.bz2
  481.  
  482. echo "\t\t\tRelease - $archi"
  483. echo "Archive: $distrib" > $Dir/Release
  484. echo "Version: $Version_distrib" >> $Dir/Release
  485. echo "Components: cairo-dock" >> $Dir/Release
  486. echo "Origin: Cairo-Dock Team" >> $Dir/Release
  487. echo "Label: Ubuntu" >> $Dir/Release
  488. echo "Architectures: $archi" >> $Dir/Release
  489. done
  490.  
  491. # create Release file
  492. echo "\n\t\tRelease : $distrib"
  493. echo "Origin: Cairo-Dock Team" > $MainDir/../Release_$distrib
  494. echo "Label: Ubuntu" >> $MainDir/../Release_$distrib
  495. echo "Suite: $distrib" >> $MainDir/../Release_$distrib
  496. echo "Version: $Version_distrib" >> $MainDir/../Release_$distrib
  497. echo "Codename: $distrib" >> $MainDir/../Release_$distrib
  498. echo "Architectures: $Architecture" >> $MainDir/../Release_$distrib
  499. echo "Components: cairo-dock" >> $MainDir/../Release_$distrib
  500. echo "Description: $Description_distrib" >> $MainDir/../Release_$distrib
  501.  
  502. echo "\t\t\tMD5, SHA1 et SHA256 : $distrib"
  503. apt-ftparchive release $MainDir >> $MainDir/../Release_$distrib
  504. mv $MainDir/../Release_$distrib $MainDir/Release
  505.  
  506. echo "\t\t\tRelease.gpg : $distrib\n\n"
  507. # sign Release file
  508. gpg --sign -u $CD_key -bao $MainDir/Release.gpg $MainDir/Release
  509. done
  510. }
  511.  
  512. packages_questions() {
  513. packages
  514. read -p "Create release and Packages files? [O/n]" suite
  515. if test "$suite" = "n" -o "$suite" = "N"; then
  516. echo "Stop"
  517. exit 0
  518. fi
  519. repository
  520. }
  521.  
  522. ## Main ##
  523.  
  524. if [ "$ARG1" = "-p" ]; then
  525. packages
  526. repository
  527. else
  528. echo "Structure needed for a repository:
  529. \t|-dists
  530. \t|-----|-'distrib' (-> $Ubuntu_Distrib)
  531. \t|-----|-----|-pool
  532. \t|-----|-----|-----|-all
  533. \t|-----|-----|-----|-----|-cairo-dock
  534. \t|-----|-----|-----|-----|-cairo-dock-plug-ins
  535. \t|-----|-----|-----|-'architecture' (-> $Architecture)
  536. \t|-----|-----|-----|-----|-cairo-dock
  537. \t|-----|-----|-----|-----|-cairo-dock-plug-ins
  538. Possibility to automatically create this tree if we have all deb packages in:
  539. \t|-Incoming
  540. \t|-----|-cairo-dock
  541. \t|-----|-cairo-dock-plug-ins
  542. Repository for Ubuntu:
  543. \tversions : $Ubuntu_Distrib
  544. \tarchitectures : $Architecture
  545.  
  546. Create release and Packages [O] / Just create directories in dists [d]
  547. Move packages from Incoming -> dists [p] / Stop [n]\t\t=> [O/d/p/n]"
  548. read pause
  549. if test "$pause" = "n" -o "$pause" = "N"; then
  550. exit 0
  551. elif test "$pause" = "d" -o "$pause" = "D"; then
  552. directories
  553. elif test "$pause" = "p" -o "$pause" = "P"; then
  554. packages_questions
  555. else
  556. repository
  557. fi
  558. fi
  559.  
  560.  
  561.  
  562. ######################################
  563. ######################################
  564. ######################################
  565. ######################################
  566. ######################################
  567. ######################################
  568.  
  569.  
  570.  
  571. Changing bash prompt
  572.  
  573. ← Using aliases Home Setting shell options →
  574.  
  575. Task: You need to customize your bash prompt by editing PS1 variable.
  576. Display, your current prompt setting, enter:
  577.  
  578. echo $PS1
  579.  
  580. Sample outputs:
  581.  
  582. \u@\h:\w\$
  583.  
  584. For testing purpose set PS1 as follows and notice the change:
  585.  
  586. PS1='your wish is my command : '
  587.  
  588. Sample outputs:
  589.  
  590. vivek@vivek-desktop:~$ PS1='your wish is my command : '
  591. your wish is my command :
  592.  
  593. Contents
  594.  
  595. 1 Customizing Prompt
  596. 2 Adding color to prompt
  597. 3 How do I make prompt setting permanent?
  598. 4 PROMPT_COMMAND variable
  599. 4.1 Creating complex prompt
  600. 5 References
  601. 6 External links
  602.  
  603. Customizing Prompt
  604.  
  605. Bash shell allows prompt strings to be customized by inserting a number of backslash-escaped special characters. Quoting from the bash man page:
  606. Sequence Description
  607. \a An ASCII bell character (07)
  608. \d The date in "Weekday Month Date" format (e.g., "Tue May 26")
  609. \e An ASCII escape character (033)
  610. \h The hostname up to the first .
  611. \H The hostname (FQDN)
  612. \j The number of jobs currently managed by the shell
  613. \l The basename of the shell’s terminal device name
  614. \n Newline
  615. \r Carriage return
  616. \s The name of the shell, the basename of $0 (the portion following the final slash)
  617. \t The current time in 24-hour HH:MM:SS format
  618. \T The current time in 12-hour HH:MM:SS format
  619. \@ The current time in 12-hour am/pm format
  620. \A The current time in 24-hour HH:MM format
  621. \u The username of the current user
  622. \v The version of bash (e.g., 2.00)
  623. \V T The release of bash, version + patch level (e.g., 2.00.0)
  624. \w The current working directory, with $HOME abbreviated with a tilde
  625. \W The basename of the current working directory, with $HOME abbreviated with a tilde
  626. \! The history number of this command
  627. \# The command number of this command
  628. \$ If the effective UID is 0, a #, otherwise a $
  629. \nnn The character corresponding to the octal number nnn
  630. \\ A backslash
  631. \[ Begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
  632. \] End a sequence of non-printing characters
  633.  
  634. You can use above backslash-escaped sequence to display name of the host with current working directory:
  635.  
  636. PS1='\h \W $ '
  637.  
  638. Adding color to prompt
  639.  
  640. It is quite easy to add colors to your prompt. Set green color prompt for normal user account[1]:
  641.  
  642. export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
  643.  
  644. And red color prompt for root user account:
  645.  
  646. export PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] '
  647.  
  648. How do I make prompt setting permanent?
  649.  
  650. Edit your ~/.bashrc or ~/.bash_profile
  651.  
  652. vi ~/.bashrc
  653.  
  654. Append your PS1 definition:
  655.  
  656. export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
  657.  
  658. Save and close the file.
  659. PROMPT_COMMAND variable
  660.  
  661. If PROMPT_COMMAND environment variable set, the value is executed as a command prior to issuing each primary prompt. In other words, the contents of this variable are executed as a regular Bash command just before Bash displays a prompt[2]:
  662.  
  663. PROMPT_COMMAND="echo Yahooo"
  664.  
  665. Sample outputs:
  666.  
  667. [vivek@vivek-desktop man]$ PROMPT_COMMAND="echo Yahooo"
  668. Yahooo
  669. [vivek@vivek-desktop man]$ date
  670. Tue Oct 20 23:50:01 IST 2009
  671. Yahooo
  672.  
  673. Creating complex prompt
  674.  
  675. Edit ~/.bashrc file:
  676.  
  677. vi ~/.bashrc
  678.  
  679. Add the following two shell functions[3]
  680.  
  681. bash_prompt_command() {
  682. # How many characters of the $PWD should be kept
  683. local pwdmaxlen=25
  684. # Indicate that there has been dir truncation
  685. local trunc_symbol=".."
  686. local dir=${PWD##*/}
  687. pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
  688. NEW_PWD=${PWD/#$HOME/\~}
  689. local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
  690. if [ ${pwdoffset} -gt "0" ]
  691. then
  692. NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
  693. NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
  694. fi
  695. }
  696.  
  697. bash_prompt() {
  698. case $TERM in
  699. xterm*|rxvt*)
  700. local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
  701. ;;
  702. *)
  703. local TITLEBAR=""
  704. ;;
  705. esac
  706. local NONE="\[\033[0m\]" # unsets color to term's fg color
  707.  
  708. # regular colors
  709. local K="\[\033[0;30m\]" # black
  710. local R="\[\033[0;31m\]" # red
  711. local G="\[\033[0;32m\]" # green
  712. local Y="\[\033[0;33m\]" # yellow
  713. local B="\[\033[0;34m\]" # blue
  714. local M="\[\033[0;35m\]" # magenta
  715. local C="\[\033[0;36m\]" # cyan
  716. local W="\[\033[0;37m\]" # white
  717.  
  718. # emphasized (bolded) colors
  719. local EMK="\[\033[1;30m\]"
  720. local EMR="\[\033[1;31m\]"
  721. local EMG="\[\033[1;32m\]"
  722. local EMY="\[\033[1;33m\]"
  723. local EMB="\[\033[1;34m\]"
  724. local EMM="\[\033[1;35m\]"
  725. local EMC="\[\033[1;36m\]"
  726. local EMW="\[\033[1;37m\]"
  727.  
  728. # background colors
  729. local BGK="\[\033[40m\]"
  730. local BGR="\[\033[41m\]"
  731. local BGG="\[\033[42m\]"
  732. local BGY="\[\033[43m\]"
  733. local BGB="\[\033[44m\]"
  734. local BGM="\[\033[45m\]"
  735. local BGC="\[\033[46m\]"
  736. local BGW="\[\033[47m\]"
  737.  
  738. local UC=$W # user's color
  739. [ $UID -eq "0" ] && UC=$R # root's color
  740.  
  741. PS1="$TITLEBAR ${EMK}[${UC}\u${EMK}@${UC}\h ${EMB}\${NEW_PWD}${EMK}]${UC}\\$ ${NONE}"
  742. # without colors: PS1="[\u@\h \${NEW_PWD}]\\$ "
  743. # extra backslash in front of \$ to make bash colorize the prompt
  744. }
  745. # init it by setting PROMPT_COMMAND
  746. PROMPT_COMMAND=bash_prompt_command
  747. bash_prompt
  748. unset bash_prompt
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765. Executing Kate as root is not possible. To edit files as root use:
  766. SUDO_EDITOR=kate sudoedit <file>
  767.  
  768.  
  769.  
  770. ######################################
  771. ######################################
  772. ######################################
  773. ######################################
  774. ######################################
  775. ############################################################################
  776. ######################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement