Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename item* to step*. #192

Merged
merged 9 commits into from
Jun 2, 2024
Merged

Conversation

azriel91
Copy link
Owner

@azriel91 azriel91 commented Jun 2, 2024

This performs the rename, but doesn't go through with it (it reverts the changes).

Details will be on #187.

let term_search = 'item'
let term_replace = 'step'

# Rename directories
(
    fd -Ftd $term_search
    | lines
    | each {|dir_old|
        let dir_new = (echo $dir_old | str reverse | str replace ($term_search | str reverse) ($term_replace | str reverse) | str reverse)
        {
            dir_old: $dir_old
            dir_new: $dir_new
        }
    }
    | insert dir_name_length {|row| $row.dir_old | str length }
    | sort-by dir_name_length --reverse
    | each {|row| mv $row.dir_old $row.dir_new}
)

# rename files
(
    fd -Ftf $term_search
    | lines
    | each {|dir_old|
        let dir_new = (echo $dir_old | str reverse | str replace ($term_search | str reverse) ($term_replace | str reverse) | str reverse)
        {
            dir_old: $dir_old
            dir_new: $dir_new
        }
    }
    | insert dir_name_length {|row| $row.dir_old | str length }
    | sort-by dir_name_length --reverse
    | each {|row| mv $row.dir_old $row.dir_new}
)

# TODO
let item_rename_dir = [$env.TEMP item_rename] | path join
if not ($item_rename_dir | path exists) { mkdir $item_rename_dir }
let matches_item_file = $item_rename_dir | path join matches_item
# rg -Fi 'item' o> $matches_item_file
let matches_item_ignores = ([
    'align-item',
    'list-item',
    'list_aligned_item',
    'list of named items',
    'item in the list',
])
let match_item_ignores_str = $"($matches_item_ignores | each {|s| $"\(($s)\)"} | str join '|')"
let matches_item = (
    open $matches_item_file --raw
    | rg -v $match_item_ignores_str
    | lines
    | parse "{file}:{text}"
    | where file != 'CHANGELOG.md' and file != 'doc\src\learning_material\empathetic_code_design.md'
)

let replacements = (
    [
        [term replacement];
        ['an Item'   'a Step'  ]
        ['an [`Item' 'a [`Step']
        ['an [item'  'a [step' ]
        ['an `Item'  'a `Step' ]
        ['an item'   'a step'  ]
        [item step]
        [Item Step]
        [StepStruct ItemStruct]
        ['Iterator<Step' 'Iterator<Item']
        ['Stream<Step' 'Stream<Item']
        ['step_interrupt_poll' 'item_interrupt_poll']
        ['interrupted_next_step_include' 'interrupted_next_item_include']
        ['list_aligned_step_write' 'list_aligned_item_write']
        ['New-Step' 'New-Item']
        ['Remove-Step' 'Remove-Item']
        ['reorder_impl_steps' 'reorder_impl_items']
        ['step_struct' 'item_struct']
        ['get_step' 'get_item']
        ['set_step' 'set_item']
        ['remove_step' 'remove_item']
        ['GetStep' 'GetItem']
        ['RemoveStep' 'RemoveItem']
        ['SetStep' 'SetItem']
    ]
)
(
    $replacements
    | each {|entry|
        sd -s $"($entry.term)" $"($entry.replacement)" ...(
            $matches_item
            | get file
            | sort
            | uniq
        )
    }
)

# TODO:
# step_wrapper.rs: change `I` to `S`.

@azriel91 azriel91 changed the title Rename item* directories to step*. Rename item* to step*. Jun 2, 2024
@azriel91 azriel91 merged commit a0acfb9 into main Jun 2, 2024
11 checks passed
@azriel91 azriel91 deleted the maintenance/187/rename-item-to-step-spike branch June 2, 2024 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant