diff --git a/input.cpp b/input.cpp index f3d752a90..b587fcbac 100644 --- a/input.cpp +++ b/input.cpp @@ -115,6 +115,9 @@ static const wchar_t * const name_arr[] = L"self-insert", L"transpose-chars", L"transpose-words", + L"upcase-word", + L"downcase-word", + L"capitalize-word", L"null", L"eof", L"vi-arg-digit", @@ -201,6 +204,9 @@ static const wchar_t code_arr[] = R_SELF_INSERT, R_TRANSPOSE_CHARS, R_TRANSPOSE_WORDS, + R_UPCASE_WORD, + R_DOWNCASE_WORD, + R_CAPITALIZE_WORD, R_NULL, R_EOF, R_VI_ARG_DIGIT, diff --git a/input.h b/input.h index 465d50473..c5722b2fc 100644 --- a/input.h +++ b/input.h @@ -44,6 +44,9 @@ enum R_SELF_INSERT, R_TRANSPOSE_CHARS, R_TRANSPOSE_WORDS, + R_UPCASE_WORD, + R_DOWNCASE_WORD, + R_CAPITALIZE_WORD, R_VI_ARG_DIGIT, R_VI_DELETE_TO, R_EXECUTE, diff --git a/reader.cpp b/reader.cpp index c8e28bfa8..de0b36793 100644 --- a/reader.cpp +++ b/reader.cpp @@ -3790,7 +3790,43 @@ const wchar_t *reader_readline(void) } break; } - + + case R_UPCASE_WORD: + { + size_t pos = data->buff_pos; + move_word(MOVE_DIR_RIGHT, false, move_word_style_punctuation, false); + for (; pos < data->buff_pos; pos++) + data->command_line.at(pos) = towupper(data->command_line.at(pos)); + reader_repaint(); + break; + } + + case R_DOWNCASE_WORD: + { + size_t pos = data->buff_pos; + move_word(MOVE_DIR_RIGHT, false, move_word_style_punctuation, false); + for (; pos < data->buff_pos; pos++) + data->command_line.at(pos) = towlower(data->command_line.at(pos)); + reader_repaint(); + break; + } + + case R_CAPITALIZE_WORD: + { + size_t pos = data->buff_pos; + bool capitalized_first = false; + move_word(MOVE_DIR_RIGHT, false, move_word_style_punctuation, false); + for (; pos < data->buff_pos; pos++) { + if (iswalnum(data->command_line.at(pos)) && !capitalized_first) { + data->command_line.at(pos) = towupper(data->command_line.at(pos)); + capitalized_first = true; + } else + data->command_line.at(pos) = towlower(data->command_line.at(pos)); + } + reader_repaint(); + break; + } + /* Other, if a normal character, we add it to the command */ default: { diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index f610e8915..ff3d6faa9 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -70,6 +70,10 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fis bind \cb backward-char bind \ct transpose-chars bind \et transpose-words + bind \eu upcase-word + # This clashes with __fish_list_current_token + # bind \el downcase-word + bind \ec capitalize-word bind \e\x7f backward-kill-word bind \eb backward-word bind \ef forward-word