From ccd02866f67e704cd4844029c0f5787c0714e21c Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Sun, 15 Apr 2018 12:44:48 -0400 Subject: Fix git_commits_{ahead,before} when no upstream branch is defined (#6658) If @{u} is not defined, git rev-list will give an error; redirect to stderr the error and deal with this case in what follows. --- lib/git.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/git.zsh b/lib/git.zsh index 9b0f6e36f..b55b762d7 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -77,8 +77,8 @@ function git_current_branch() { # Gets the number of commits ahead from remote function git_commits_ahead() { if command git rev-parse --git-dir &>/dev/null; then - local commits="$(git rev-list --count @{upstream}..HEAD)" - if [[ "$commits" != 0 ]]; then + local commits="$(git rev-list --count @{upstream}..HEAD 2>/dev/null)" + if [[ -n "$commits" && "$commits" != 0 ]]; then echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" fi fi @@ -87,8 +87,8 @@ function git_commits_ahead() { # Gets the number of commits behind remote function git_commits_behind() { if command git rev-parse --git-dir &>/dev/null; then - local commits="$(git rev-list --count HEAD..@{upstream})" - if [[ "$commits" != 0 ]]; then + local commits="$(git rev-list --count HEAD..@{upstream} 2>/dev/null)" + if [[ -n "$commits" && "$commits" != 0 ]]; then echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX" fi fi -- cgit v1.2.3-70-g09d2 From d87d4331cfab6cffbcc2366a855855b9a5c5e848 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 15 Jun 2014 21:08:04 +0200 Subject: Change history alias into a function This commit changes the history alias into a function which puts the passed arguments before `-l 1`. It also provides a temporary workaround to the lack of a `history -c` command in zsh. For more information see issues 739 and 789. --- lib/history.zsh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/history.zsh b/lib/history.zsh index 5de71c2d3..8a861fdbc 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -6,12 +6,24 @@ fi HISTSIZE=10000 SAVEHIST=10000 -# Show history +## History wrapper +function omz_history { + # Delete the history file if `-c' argument provided. + # This won't affect the `history' command output until the next login. + if [[ "${@[(i)-c]}" -le $# ]]; then + echo -n >| "$HISTFILE" + echo >&2 History file deleted. Reload the session to see its effects. + else + fc $@ -l 1 + fi +} + +# Timestamp format case $HIST_STAMPS in - "mm/dd/yyyy") alias history='fc -fl 1' ;; - "dd.mm.yyyy") alias history='fc -El 1' ;; - "yyyy-mm-dd") alias history='fc -il 1' ;; - *) alias history='fc -l 1' ;; + "mm/dd/yyyy") alias history='omz_history -f' ;; + "dd.mm.yyyy") alias history='omz_history -E' ;; + "yyyy-mm-dd") alias history='omz_history -i' ;; + *) alias history='omz_history' ;; esac setopt append_history -- cgit v1.2.3-70-g09d2 From 94baa9eadd05038a343bfd99f01493123f5a1526 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 13 Dec 2014 23:20:03 +0100 Subject: Simplify `if' into oneliner, allow spaces in HISTFILE --- lib/history.zsh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/history.zsh b/lib/history.zsh index 8a861fdbc..058a1a319 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -1,8 +1,5 @@ ## Command history configuration -if [ -z "$HISTFILE" ]; then - HISTFILE=$HOME/.zsh_history -fi - +[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" HISTSIZE=10000 SAVEHIST=10000 -- cgit v1.2.3-70-g09d2 From 643bb25a0d2bd5c2ef316a88021e1ac4eb156bf8 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 13 Dec 2014 23:31:56 +0100 Subject: Organize history.zsh file and improve comments --- lib/history.zsh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/history.zsh b/lib/history.zsh index 058a1a319..da1e02ddf 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -1,8 +1,3 @@ -## Command history configuration -[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" -HISTSIZE=10000 -SAVEHIST=10000 - ## History wrapper function omz_history { # Delete the history file if `-c' argument provided. @@ -23,11 +18,17 @@ case $HIST_STAMPS in *) alias history='omz_history' ;; esac -setopt append_history -setopt extended_history -setopt hist_expire_dups_first -setopt hist_ignore_dups # ignore duplication command history list -setopt hist_ignore_space -setopt hist_verify -setopt inc_append_history -setopt share_history # share command history data +## History file configuration +[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" +HISTSIZE=10000 +SAVEHIST=10000 + +## History command configuration +setopt append_history # append history to HISTFILE on session exit +setopt extended_history # record timestamp of command in HISTFILE +setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE +setopt hist_ignore_dups # ignore duplicated commands history list +setopt hist_ignore_space # ignore commands that start with space +setopt hist_verify # show command with history expansion to user before running it +setopt inc_append_history # add commands to HISTFILE in order of execution +setopt share_history # share command history data -- cgit v1.2.3-70-g09d2 From 03758416fe99f0f1cb9f19ad1a7846de1b02f21a Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 18 Dec 2014 12:08:56 +0100 Subject: Ensure builtin fc is used (see #3001) --- lib/history.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/history.zsh b/lib/history.zsh index da1e02ddf..21e9c7563 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -6,7 +6,7 @@ function omz_history { echo -n >| "$HISTFILE" echo >&2 History file deleted. Reload the session to see its effects. else - fc $@ -l 1 + builtin fc "$@" -l 1 fi } -- cgit v1.2.3-70-g09d2 From f8180c3a64754057d696a4fb1cf3639c394377b9 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 18 Dec 2014 20:36:56 +0100 Subject: Allow overriding -l flag in history --- lib/history.zsh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/history.zsh b/lib/history.zsh index 21e9c7563..e6c94fcc0 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -5,6 +5,8 @@ function omz_history { if [[ "${@[(i)-c]}" -le $# ]]; then echo -n >| "$HISTFILE" echo >&2 History file deleted. Reload the session to see its effects. + elif [[ "${@[(i)-l]}" -le $# ]]; then + builtin fc "$@" else builtin fc "$@" -l 1 fi -- cgit v1.2.3-70-g09d2 From 20d63be655bfed2104858dc87052a310f9c45224 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 18 Dec 2014 21:56:49 +0100 Subject: Use zparseopts to get passed arguments --- lib/history.zsh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/history.zsh b/lib/history.zsh index e6c94fcc0..23e96c9db 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -2,12 +2,18 @@ function omz_history { # Delete the history file if `-c' argument provided. # This won't affect the `history' command output until the next login. - if [[ "${@[(i)-c]}" -le $# ]]; then + zparseopts -E c=clear l=list + + if [[ -n "$clear" ]]; then + # if -c provided, clobber the history file echo -n >| "$HISTFILE" echo >&2 History file deleted. Reload the session to see its effects. - elif [[ "${@[(i)-l]}" -le $# ]]; then + elif [[ -n "$list" ]]; then + # if -l provided, run as if calling `fc' directly builtin fc "$@" else + # otherwise, call `fc -l 1` to show all available + # history (and pass additional parameters) builtin fc "$@" -l 1 fi } -- cgit v1.2.3-70-g09d2 From 9f2f22d953acc62a2a0ba5f08a746e47be3a6d4e Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 22 Apr 2018 15:25:30 +0200 Subject: Remove duplicate option append_history The option inc_append_history already has the same effect. --- lib/history.zsh | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/history.zsh b/lib/history.zsh index 23e96c9db..8a1bc010d 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -32,7 +32,6 @@ HISTSIZE=10000 SAVEHIST=10000 ## History command configuration -setopt append_history # append history to HISTFILE on session exit setopt extended_history # record timestamp of command in HISTFILE setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE setopt hist_ignore_dups # ignore duplicated commands history list -- cgit v1.2.3-70-g09d2 From 2589cdd8f9603d03f5b84aab57fda96ac0259f79 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 22 Apr 2018 15:26:57 +0200 Subject: Increment HISTSIZE to fix hist_expire_dups_first This fixes the old behavior which made it so all duplicates would be deleted if the command history filled up with unique events. > You should be sure to set the value of HISTSIZE to a larger number > than SAVEHIST in order to give you some room for the duplicated > events, otherwise this option will behave just like HIST_IGNORE_ALL_DUPS > once the history fills up with unique events. --- lib/history.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/history.zsh b/lib/history.zsh index 8a1bc010d..7d4e59d00 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -28,7 +28,7 @@ esac ## History file configuration [ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" -HISTSIZE=10000 +HISTSIZE=50000 SAVEHIST=10000 ## History command configuration -- cgit v1.2.3-70-g09d2 From 93d9431890540dfdc1021dffca3eeebdc19d338d Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 24 Apr 2018 23:47:26 +0200 Subject: Check for Microsoft's WSL in open_command (#6751) This will work only on files and directories in a DrvFs mount, i.e. that can be translated to a Windows drive path. For example: /mnt/c/Users/user. Files and folders inside the LXSS directory can't be handled in Windows, they must be ONLY used by the WSL subsystem. That's why you won't be able to open your $HOME directory, for instance. See https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/ --- lib/functions.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/functions.zsh b/lib/functions.zsh index f30653784..7410ae645 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -25,7 +25,9 @@ function open_command() { case "$OSTYPE" in darwin*) open_cmd='open' ;; cygwin*) open_cmd='cygstart' ;; - linux*) open_cmd='xdg-open' ;; + linux*) [[ $(uname -a) =~ "Microsoft" ]] && \ + open_cmd='cmd.exe /c start' || \ + open_cmd='xdg-open' ;; msys*) open_cmd='start ""' ;; *) echo "Platform $OSTYPE not supported" return 1 -- cgit v1.2.3-70-g09d2